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)
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)
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)