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

Collecting a coin occasionally gives two points?

I know why this is happening I just need to figure out how to make the script disable after its collected without it interfering with the part of the script that deletes the part.

Code:

script.Parent.Touched:connect(function(c)
game.Players.LocalPlayer.leaderstats.VCoins.Value = game.Players.LocalPlayer.leaderstats.VCoins.Value + 1
	wait(0)
	script.Parent:Destroy()
end)

help please

2 answers

✓ Accepted answer

You need a debounce, debounces make sure that it doesn't play the code twice

http://wiki.roblox.com/index.php?title=Debounce

touched = true
script.Parent.Touched:connect(function(c)
if touched == true then
	game.Players.LocalPlayer.leaderstats.VCoins.Value = game.Players.LocalPlayer.leaderstats.VCoins.Value + 1
touched = false
	    wait(.2)
touched = true
	    script.Parent:Destroy()
	end)

1 comment

0

forgot a end but it works ty!

Debounce. Check if the variable is false. If yes, then set it to true. Then award points. This will only execute ONCE.

EDIT:

local debounce = false

event:function()
	if debounce ~= true then
		debounce = false
		-- stuff
	end
end

9 comments

0

Never used Debounce before. Code?

0

done.

0

One last thing, could you combine the two pieces of code? Because I dunno where to put the debounce.

0

Then learn lua. Too bad I have to keep this comment PG. If you can't do that, i doubt your scripting ability.

0

I am new to Lua but whatever.

0

@H4X0MSYT You're missing :Connect().

0

@Link150 its not meant to be an entire script.... Just a placeholder for a listener.

0

@H4X0MSYT Well, it still didn't work even when I put everything in the correct places.

0

@nap516 then you did it wrong.

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