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

Debounce Brick won't work?

Asked by 9 years ago

I want to make it so when a Player hits a brick, it gives them 1 Player Point, not 8... Anyways, here's the script.

local buttonPressed = false

local How_Much_To_Award = 1 -- How much Player Points to award.
script.Parent.Touched:connect(function(plr)
    if not buttonPressed then
        buttonPressed = true
    end
    wait()
    local i = plr.Parent.Name
    if plr.Parent:findFirstChild("Humanoid") then
    print(plr.Parent.Name)
    game:GetService("PointsService"):AwardPoints(game.Players:findFirstChild(i).userId, How_Much_To_Award)
    buttonPressed = false
    print("Done.")
    end
end)

1 answer

Log in to vote
1
Answered by
Sublimus 992 Moderation Voter
9 years ago

You don't actually have anything to keep it from running if buttonPressed is true

local buttonPressed = false

local How_Much_To_Award = 1 -- How much Player Points to award.
script.Parent.Touched:connect(function(plr)
    if buttonPressed == true then return end -- Causes the function to end here if buttonPressed is true
    buttonPressed = true
    wait()
    local i = plr.Parent.Name
    if plr.Parent:findFirstChild("Humanoid") then
    print(plr.Parent.Name)
    game:GetService("PointsService"):AwardPoints(game.Players:findFirstChild(i).userId, How_Much_To_Award)
    buttonPressed = false
    print("Done.")
    end
end)
0
It sorta slowed it down, but it still gives a lot away, is there a way to fix this? ScriptingHelpersALT 20 — 9y
0
Nevermind, I got it, thank's ScriptingHelpersALT 20 — 9y
Ad

Answer this question