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

Collecting a coin occasionally gives two points?

Asked by
nap516 87
7 years ago
Edited 7 years ago

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

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

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)
0
forgot a end but it works ty! nap516 87 — 7y
Ad
Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
7 years ago
Edited 7 years ago

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
0
Never used Debounce before. Code? nap516 87 — 7y
0
done. H4X0MSYT 536 — 7y
0
One last thing, could you combine the two pieces of code? Because I dunno where to put the debounce. nap516 87 — 7y
0
Then learn lua. Too bad I have to keep this comment PG. If you can't do that, i doubt your scripting ability. H4X0MSYT 536 — 7y
View all comments (5 more)
0
I am new to Lua but whatever. nap516 87 — 7y
0
@H4X0MSYT You're missing `:Connect()`. Link150 1355 — 7y
0
@Link150 its not meant to be an entire script.... Just a placeholder for a listener. H4X0MSYT 536 — 7y
0
@H4X0MSYT Well, it still didn't work even when I put everything in the correct places. nap516 87 — 7y
0
@nap516 then you did it wrong. H4X0MSYT 536 — 7y

Answer this question