I want to prevent this script from running more than once, so I figured if I use a debounce, that will fix my problem, but I don't know where...
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then script.Parent.Sound:Play() local player = game.Players.LocalPlayer player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 wait() script.Disabled = true script.Parent:Destroy() else wait(10) script.Parent:Destroy() end end)
local touched = false -- define your debounce script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if touched == false then touched = true script.Parent.Sound:Play() local player = game.Players.LocalPlayer player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 wait() script.Disabled = true script.Parent:Destroy() touched = false -- make it so that players can touch it again else wait(10) script.Parent:Destroy() touched = false end end end)
Hope this helped you! I might not have solved it all the way but I think this will help.