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

Where i need to add the Debounce function?

Asked by 10 years ago

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

Log in to vote
2
Answered by 10 years ago
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)


0
Can you make it a script? so its easyer to for me to copy :) brickgame38 50 — 10y
0
Hmm not sure how. TaleOfScripting 15 — 10y
0
Oh it is a script it just won't like paste, like that kind of format. TaleOfScripting 15 — 10y
0
Oh there we go. TaleOfScripting 15 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

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)


0
Also, I recommend setting the wait to a number a bit larger, otherwise the function will just run again 0.1 seconds afterwards. mrgeorge12345 45 — 10y
Log in to vote
-1
Answered by 10 years ago

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

Answer this question