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

Where i need to add the Debounce function?

When someone touch the block it gets multiple points for every touch and i want to add the debounce but i don't know where.

local Pts = script.Parent
Pts.Touched:connect(function(part)
local g = game.Players:GetPlayerFromCharacter(part.Parent)
if part:IsA("Part") and (g) then
pps = game:GetService("PointsService")
if pps:GetAwardablePoints() >= 0 then
    pps:AwardPoints(g.userId, 1)
wait(0.1)
end
end
end)

3 answers

✓ Accepted answer
local Pts = script.Parent
Power = false
Pts.Touched:connect(function(part)
local g = game.Players:GetPlayerFromCharacter(part.Parent)
if part:IsA("Part") and (g) then
pps = game:GetService("PointsService")
if pps:GetAwardablePoints() >= 0 and Power == false then
Power = true
pps:AwardPoints(g.userId, 1)
wait(0.1) -- Change this to the time you want them to get each point.
Power = false
end
end
end)


4 comments

0

Can you make it a script? so its easyer to for me to copy :)

0

Hmm not sure how.

0

Oh it is a script it just won't like paste, like that kind of format.

0

Oh there we go.

There are a couple ways to install debounce, but I personally like to do it this way:

local Pts = script.Parent
debounce = false
Pts.Touched:connect(function(part)
if debounce == true then return end --if the variable is true then end the function
debounce = true --sets the variable to true, so the function won't run again for a set period of time
local g = game.Players:GetPlayerFromCharacter(part.Parent)
if part:IsA("Part") and (g) then
pps = game:GetService("PointsService")
if pps:GetAwardablePoints() >= 0 then
    pps:AwardPoints(g.userId, 1)
wait(0.1)
debounce = false --the function can run again
end
end
end)


1 comment

0

Also, I recommend setting the wait to a number a bit larger, otherwise the function will just run again 0.1 seconds afterwards.

Thanks for the both answers! they both works, Thanks :D

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