Door behaving weirdly

  1. What do you want to achieve?
    I am trying to make a system where whenever I have equipped my Tool i.e RoomKey then the door will open.
  2. What is the issue?
    The Issue is that when I open the door then it starts to behave very weirdly (like disappearing instantly) even though I have said to wait for 1 second before opening it.
  3. Video
    robloxapp-20230608-2012418.wmv (2.5 MB)
  4. Code
game.Workspace.Door.Block.Touched:Connect(function(player)
	local plr = player.Parent
	local name = plr.Name
	local our_main_target = plr:FindFirstChild("RoomKey")
	if	our_main_target then
		wait(1)
		game.Workspace.Door.Block.Transparency = 1
		game.Workspace.Door.Handle.Transparency = 1
		game.Workspace.Door.Block.CanCollide = false
		game.Workspace.Door.Handle.CanCollide = false
		wait(5)
		game.Workspace.Door.Block.Transparency = 0
		game.Workspace.Door.Handle.Transparency = 0
		game.Workspace.Door.Block.CanCollide = true
		game.Workspace.Door.Handle.CanCollide = true
	end
	
end)

What am I doing wrong?

You need to add a debounce
such that .Touched doesn’t keep firing

1 Like

what is a debounce? how do I add it?

local Debounce = false
game.Workspace.Door.Block.Touched:Connect(function(player)
	if not Debounce then
		local plr = player.Parent
		local name = plr.Name
		local our_main_target = plr:FindFirstChild("RoomKey")
		if our_main_target then
			Debounce = true
			wait(1)
			game.Workspace.Door.Block.Transparency = 1
			game.Workspace.Door.Handle.Transparency = 1
			game.Workspace.Door.Block.CanCollide = false
			game.Workspace.Door.Handle.CanCollide = false
			wait(5)
			game.Workspace.Door.Block.Transparency = 0
			game.Workspace.Door.Handle.Transparency = 0
			game.Workspace.Door.Block.CanCollide = true
			game.Workspace.Door.Handle.CanCollide = true
			Debounce = false
		end
	end
end)

It’s sort of like a cooldown

1 Like
local debounce = false
game.Workspace.Door.Block.Touched:Connect(function(player)
	local plr = player.Parent
	local name = plr.Name
	local our_main_target = plr:FindFirstChild("RoomKey")
	if	our_main_target then
if debounce then return end
debounce = true
		wait(1)
		game.Workspace.Door.Block.Transparency = 1
		game.Workspace.Door.Handle.Transparency = 1
		game.Workspace.Door.Block.CanCollide = false
		game.Workspace.Door.Handle.CanCollide = false
		wait(5)
		game.Workspace.Door.Block.Transparency = 0
		game.Workspace.Door.Handle.Transparency = 0
		game.Workspace.Door.Block.CanCollide = true
		game.Workspace.Door.Handle.CanCollide = true
debounce = false
	end
	
end)

Okay thank you so much
I appreciate your help!

Okay thank you so much
I appreciate your help!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.