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

Is there any way to make this brick destroy after it gives 1 coin?

Asked by 7 years ago

I have a script that I want to destroy after it gives the player 1 coin.Does anybody know a script for that? Script: script.Parent.Touched:connect(function(part) if game.Players:findFirstChild(part.Parent.Name) then local plr = game.Players:findFirstChild(part.Parent.Name) plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1 end end)

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

When you want to destroy it all you literally do is use the :Destroy() function. Also, I have added a debounce that basically makes sure the player only gets 1 coin instead of hundreds.

If this is what you were looking for please make sure to accept my answer

local debounce = true
script.Parent.Touched:connect(function(part) 
    if debounce then
        debounce = false
        if game.Players:findFirstChild(part.Parent.Name) then 
            local plr = game.Players:findFirstChild(part.Parent.Name) 
            plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1
            script.Parent:Destroy()
        end     
    end
end)
Ad

Answer this question