so i am being a dumbo is not know what doing. so i want this so when its touched it only gives the amount once but right now it gives it multiple times i have tried adding a wait but it made the problem worse. any idea how i would stop the script from giving to much?
amnt = 10 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("PlayerStats")
if (stats~=nil) then
local score = stats:findFirstChild("Coins")
if (score~=nil) then -- wait was here but i removed it score.Value = score.Value + amnt
end
end
end
script.Parent.Position = Vector3.new(2.581, -3.211, 19.357)
wait(10)
script.Parent.Position = Vector3.new(2.581, 1.5, 19.357)
end
end
script.Parent.Touched:connect(onTouched)
ok so i looked up a debounce tutorial and i found one and implemented it into my code heres what it is now and it works i also figured out how to do that code thing thanks for letting me know what to do
local Debounce = false amnt = 10 --how much you get for it function onTouched(part) if not Debounce then Debounce = true local h = part.Parent:findFirstChild("Humanoid") if (h~=nil) then local thisplr = game.Players:findFirstChild(h.Parent.Name) if (thisplr~=nil) then local stats = thisplr:findFirstChild("PlayerStats") if (stats~=nil) then local score = stats:findFirstChild("Coins") if (score~=nil) then score.Value = score.Value + amnt end end end script.Parent.Position = Vector3.new(2.581, -3.211, 19.357) wait(10) script.Parent.Position = Vector3.new(2.581, 1.5, 19.357) Debounce = false end end end script.Parent.Touched:connect(onTouched)