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)
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)
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?