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

Why doesn't this DEBOUNCE?

Asked by 10 years ago
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.

0
In between lines 18-19, move the wait(60)and press = false in between those lines. TheeDeathCaster 2368 — 10y

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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)

Ad

Answer this question