Hello. I made this team script, and it will not work if I add debounce. I tested the script with prints and when it comes to the part where it finds the humanoid it won't work. Here is my script: I have some other locals, but that doesn't matter. The locals are assigned for teams.
local door = script.Parent local debounce = false door.Touched:Connect(function(hit) if debounce == false then debounce = true local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr.Team == Republic then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) debounce = false elseif plr.Team == RI then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) debounce = false elseif plr.Team == BlueTeam then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) debounce = false elseif plr.Team == CG then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) debounce = false elseif plr.Team == RG then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) debounce = false elseif plr.Team == RC then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) debounce = false end end end end)
Hope you can help, thank you.
This happen because when a thing that doesn't has a Humanoid touched the door, debounce
will set true then if-then will check is the thing touched has Humanoid but it dosen't has so the debounce = false
line inside every if-then won't run. The next time something touch the door the rest of the code won't run because debounce
is still true.
local debounce = false door.Touched:Connect(function(hit) if debounce == false then debounce = true local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr.Team == Republic then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) elseif plr.Team == RI then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) elseif plr.Team == BlueTeam then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) elseif plr.Team == CG then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) debounce = false elseif plr.Team == RG then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) elseif plr.Team == RC then door.CanCollide = false door.Transparency = .3 wait(1) door.CanCollide = true door.Transparency = .5 wait(1) end end debounce = false end end)
Likely because the debounce variable is supposed to only be mutated whenever there is a humanoid within the touching object AND if any of the plr.Team conditions are satisfied. If the player is in none of those teams, it won't be set to false.