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

Debounce not working?

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

I have a debounce that should make it take 5 seconds to use this hopperbin again. However, it doesn't work! It works a little, but not for 5 seconds. Please help.

local tool = script.Parent 
local plr = tool.Parent.Parent
local db = false

tool.Selected:connect(function(mouse)
    mouse.Button1Down:connect(function()
        if db == false then
            db = true
            local target = mouse.Target
            print(target)
            if game.Players:GetPlayerFromCharacter(target.Parent) then
                if (target.Parent.Torso.Position - plr.Character.Torso.Position).magnitude <= 7 then
                    target.Parent.Torso.Velocity = plr.Character.Torso.CFrame.lookVector * 150
                end
            end 
        end
        wait(5)
        db = false
    end)
end)

3 answers

Log in to vote
1
Answered by
Lacryma 548 Moderation Voter
10 years ago

The problem is that you added the wait and db= false onto the wrong scope. Try now.

local tool = script.Parent 
local plr = tool.Parent.Parent
local db = false

tool.Selected:connect(function(mouse)
    mouse.Button1Down:connect(function()
        if not db then
            db = true
            local target = mouse.Target
            print(target)
            if game.Players:GetPlayerFromCharacter(target.Parent) then
                if (target.Parent.Torso.Position - plr.Character.Torso.Position).magnitude <= 7 then
                    target.Parent.Torso.Velocity = plr.Character.Torso.CFrame.lookVector * 150
                end
            end 
        wait(5)
        db = false
end
    end)
end)
0
Thanks! Perci1 4988 — 10y
Ad
Log in to vote
-1
Answered by
KAAK82 16
10 years ago

all u gotta do is

touching = false

function() if not touching then touching = true --code touching = false

or if it's other stuff then u can rename the touching...

Log in to vote
-3
Answered by 10 years ago

I'm thinking instead of putting db put the actual word "debounce". Maybe that would work.

0
It does not Matter what word you do for Debounce. You could do anything. I'm pretty sure... starkiller523 65 — 10y

Answer this question