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

Debounce not working?

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

✓ Accepted answer

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)

1 comment

0

Thanks!

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

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

1 comment

0

It does not Matter what word you do for Debounce. You could do anything. I'm pretty sure...

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