Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i stop the coin from giving to much money?

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)

5 comments

0

ahem debounce

0

yeah... break ; debounce

0

Nice job pasting in the correct script this time, but you still haven't put it in code blocks like we told you last time. That wasn't a one time thing, so you should always put your code in code blocks here.

0

how do that

0

both things

1 answer

✓ Accepted answer

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)

1 comment

0

a debounce tutorial huh

This discussion is preserved as it was. New answers, comments, and votes are closed.