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

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

Asked by 5 years ago
Edited 5 years ago

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)

0
*ahem* debounce DeceptiveCaster 3761 — 5y
0
yeah... break ; debounce AltNature 169 — 5y
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. SteamG00B 1633 — 5y
0
how do that MPforfun 91 — 5y
0
both things MPforfun 91 — 5y

1 answer

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

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)
0
a debounce tutorial huh Deadman7117 46 — 5y
Ad

Answer this question