Script not woking

I am trying to make a local button, but whenever the debounce ends, you can’t press it anymore. I have tried putting the debounce in the script inside of the part, but then the other player cannot press it until the debounce ends.

Script in Part:

local part = script.Parent
local re = script.Parent.RemoteEvent
part.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	re:FireClient(plr)
end)

Local Script:

local re = game.Workspace.Part.RemoteEvent
local text = script.Parent
local value = script.Parent.Value
local timer = script.Parent.Time
local db = false
re.OnClientEvent:Connect(function()
	if not db then
		db = true
		re.Parent.button3:Play()
		game.Workspace.Wall.Transparency = 0.8
		game.Workspace.Wall.CanCollide = false
		repeat
			text.Text = timer.Value
			timer.Value = timer.Value - 1
			wait(1)
		until timer.Value == -1
		if timer.Value == -1 then
			text.Text = ""
			timer.Value = 15
			game.Workspace.Wall.Transparency = 0
			game.Workspace.Wall.CanCollide = true
		end
		wait(15)
		db = false
	end
end)

Are there any errors at all? If not, could you add print statements to check where the code ends?

I would put a debounce in the Part Script ALSO, otherwise it could cause issues with trying to execute the remote function lots of times for the same player touching it:

local part = script.Parent
local re = script.Parent.RemoteEvent
local db=false
part.Touched:Connect(function(hit)
	if db==false then
    	db=true
	    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	    re:FireClient(plr)
        wait(1)
		db=false
	end
end)

There are no errors at all, even when it does not run.

I tried this, but it did not help, since it still doesn’t run, but it is a good idea.

I just tested your code and it works fine.
Are you sure your waiting the full 15 seconds after Transparency of the wall is set back to 0 before trying to touch the part again?

wait(15)
db = false

Yes, I have done that. But it still does not work.

if db == false then with not = opposite

Well if you looked at it without the variable it would say “if not false then”

its
re.OnClientEvent:Connect(function()
if db == false then

Ok, I have found the error, I was just making it wait an extra 15 seconds.

1 Like