Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

A Wait until function?(answered)

Asked by 6 years ago
Edited 6 years ago

Answered

0
Because we do not particularly take request questions. Have you looked into creating this script yourself or have you expected the community to generate the solution for you? M39a9am3R 3210 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

If you put the coins in a model/folder and call them 1, 2, 3 etc., you can do something like this in a script inside that model/folder (assuming you have a leaderstat called Coins):

for _,v in pairs(script.Parent:GetChildren()) do
    if v:IsA("BasePart") then
        v.Touched:Connect(function(hit)
            if not script.Parent:FindFirstChild(tonumber(v.Name)-1) then
                local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
                if plr and plr:FindFirstChild("leaderstats") then
                    plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1
                end
                v:Destroy()
            end
        end)
    end
end
Ad

Answer this question