#One of the coins not working

1 messages · Page 1 of 1 (latest)

mint bluff
#

One of the three coins just doesnt works and idk why

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local coin = Instance.new("IntValue")
    coin.Name = "Coins"
    coin.Parent = leaderstats
    coin.Value = 0
end)

local myCoins = game.Workspace.MainGame:WaitForChild("Coins")

for _, usingMyCoins in pairs(myCoins:GetChildren()) do
    if usingMyCoins:IsA("BasePart") then
    local coinTouched = false
    usingMyCoins.Touched:Connect(function(hit)
        if coinTouched then return end
        coinTouched = true
        local players = game.Players:GetPlayerFromCharacter(hit.Parent)
        if players and players:FindFirstChild("leaderstats") then
            players.leaderstats.Coins.Value += 1
            usingMyCoins:Destroy()
        end

    end)
    end
end```
It might be a stupid reason, Im new to this but Ill love any help
mint bluff
#

Looks like I had to move coinTouched = true inside if players...