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

Why doesn't this DEBOUNCE?

local press = false
local pointgiver = script.Parent
pointgiver.Touched:connect(function(pointgiver)
if not press then
press = true
local g = game.Players:GetPlayerFromCharacter(pointgiver.Parent)
if pointgiver:IsA("Part") and (g) then
pps = game:GetService("PointsService")
if pps:GetAwardablePoints() >= 1 then
local plr = pointgiver.Parent:findFirstChild("Humanoid")
if plr.Health == 100 then
pps:AwardPoints(g.userId, 1)
wait(60)
else
print"not humanoid"
end 
end
end
end
press = false
end)

The above script works just like it has no debounce (even though I'm pretty sure I used it correctly) and gives the player 5 times the certain amount of points rather than giving it just once when the player touches it once.

1 comment

0

In between lines 18-19, move the wait(60)and press = false in between those lines.

1 answer

I'm assuming you wanted a 60 second cool-off time so nobody else can touch it during that period, so here you go. I also fixed up the spacing.

local press = false
local pointgiver = script.Parent
pointgiver.Touched:connect(function(pointgiver)
	if not press then
		local g = game.Players:GetPlayerFromCharacter(pointgiver.Parent)
		if pointgiver:IsA("Part") and g then
			press = true
			pps = game:GetService("PointsService")
			if pps:GetAwardablePoints() >= 1 then
				local plr = pointgiver.Parent:findFirstChild("Humanoid")
				if plr.Health == 100 then
					pps:AwardPoints(g.userId, 1)
					wait(60)
					press = false
				else
					print("not humanoid")
				end 
			end
		end
	end
end)

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