Door doesn't close when player dies

Hello everyone, I made a button that when player click it a door opens and appear a count down on the screen, and I decided whether player dies the local scripts got reset but the problem is when the count down finished the door doesn’t close itself

local script inside TextLabel:

--local door = game.Workspace.Door

for i = 40,0,-1 do
		script.Parent.Text = i
	wait(1)
	
	local humanoid = player.Character:WaitForChild("Humanoid")
	humanoid.Died:Connect(function()
		script.Enabled = false
		script.Parent.Visible = false
		
	if i == 0 then
		script.Parent.Text = "Time's Up"
			wait(1)
			script.Parent.Visible = false
			
		end
	end)
end 

another local script inside StarterPlayerScripts:


local door = game.Workspace.Door

local sound = game.Workspace["Dish Sound"]["Dishes Washed"]

local sponge = game.Workspace.spomge.ClickDetector

local player = game.Players.LocalPlayer

local gui = player.PlayerGui:WaitForChild("Contador").Count.LocalScript

local text = player.PlayerGui:WaitForChild("Contador").Count

local player = game.Players.LocalPlayer

sponge.MouseClick:Connect(function(action)
	if db == false then
		db = true
		door.Transparency = 1
		door.CanCollide = false
		door.Decal1.Transparency = 1
		door.Decal2.Transparency = 1
		sound:Play()
		gui.Enabled = true
		text.Visible = true
		
		local humanoid = player.Character:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			script.Enabled = false
			door.Transparency = 0
			door.CanCollide = true
			door.Decal1.Transparency = 0
			door.Decal2.Transparency = 0
			text.Visible = false
			wait(1)
			script.Enabled = true
		wait(40)
		db = false
		door.Transparency = 0
		door.CanCollide = true
		door.Decal1.Transparency = 0
			door.Decal2.Transparency = 0
			text.Visible = false
			--gui.Enabled = false
		end)
	end
end)

Here is a demostration of the problem:

I hope you guys can help me out, thank you for your time

1 Like

Put “Humanoid.Died:Connect(Function()” out of the “Mouse.Click” script, as that may be holding it back.

2 Likes

the door stills open and close when countdown finished now @SuguruDev

Thats weird, do you mind sending me the door model really quickly so I can experiment with it?
Ill send a working version once finished.

2 Likes

well it’s not a model it’s a part with decals and canCollide itself once time player clicks a button that it’s a part too, everything worked fine but since I did the reset local script stuff it doesn’t close once the countdown finished

Mind explaining what you mean by “Does’nt reset itself”?

1 Like

when player is death the local scripts will reset but since you told me that I removed the "Humanoid.Died:Connect(Function()” now the local scripts doesn’t reset

local door = game.Workspace.Door

local sound = game.Workspace["Dish Sound"]["Dishes Washed"]

local sponge = game.Workspace.spomge.ClickDetector

local player = game.Players.LocalPlayer

local gui = player.PlayerGui:WaitForChild("Contador").Count.LocalScript

local text = player.PlayerGui:WaitForChild("Contador").Count

local player = game.Players.LocalPlayer

sponge.MouseClick:Connect(function(action)
	if db == false then
		db = true
		door.Transparency = 1
		door.CanCollide = false
		door.Decal1.Transparency = 1
		door.Decal2.Transparency = 1
		sound:Play()
		gui.Enabled = true
		text.Visible = true
	end
end)

	local humanoid = player.Character:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			door.Transparency = 0
			door.CanCollide = true
			door.Decal1.Transparency = 0
			door.Decal2.Transparency = 0
			text.Visible = false
		wait(40)
		db = false
		door.Transparency = 0
		door.CanCollide = true
		door.Decal1.Transparency = 0
			door.Decal2.Transparency = 0
			text.Visible = false
			--gui.Enabled = false
		end)
2 Likes

so this will reset the local scripts each time player is dead?

change local script to a script then put it inside player Character whene the player reset the script reset as well

1 Like

the first or the second one? ------

Try my newest edit, see if it works for you.
I just saw you were enabling then disabling the script.
The script disables its-self without being enabled.

1 Like

I tried your edit but now when I click the part it doesn’t works the whole script

1 Like

Mind giving me the line where the error is occurring on?

1 Like

it doesn’t pop up nothing in the output

Thats weird, hold on ima try to recreate your script and give you a finished version

1 Like

I just tested again your script and it didn’t work because the db was not called so I added that and it works but the problem again is the door that doesn’t close back @CloudYugen

Ty for the update, ill work on it really quickly.

1 Like

Hi @SuguruDev I just modify your script and it works perfectly, but a simple error occurs when the player clicks the button again it appears 0 (zero), it means that the text doesn’t update but the door closes at time

1 Like

Nvm, i just fix the problem!, thank you for your dearly time

1 Like