Change all of your :connect
to :Connect
, as it is the proper API reference.
Here is what your current code is doing:
For every player that joins the game, and every time their character re-spawns, you are making a new event every time their character dies, and every time their character dies, you are listening for the door humanoid to die - and when it does, you are setting the door parts transparencies to 1… then yielding for 5 minutes before setting back to 0.
from what you are explaining here:
Recently I added a feature to my door where there is a humanoid in it, and when the humanoid’s health is set to 0 the door is supposed to get destroyed, and the door’s transparency is set to 1, while the fallen door’s transparency is set to 0.
It sounds like you don’t need to have any of these player/character events at all… here is something that should do what you are saying.
doorHumanoid.Died:Connect(function()
DoorPart.Transparency = 1
DoorPart2.Transparency = 1
DoorPart3.Transparency = 1
DoorPart.CanCollide = false
DoorPart2.CanCollide = false
DoorPart3.CanCollide = false
delay(60*5, function()
doorHumanoid.Health = 100 -- or whatever
DoorPart.Transparency = 0
DoorPart2.Transparency = 0
DoorPart3.Transparency = 0
DoorPart.CanCollide = false
DoorPart2.CanCollide = false
DoorPart3.CanCollide = false
end)
end
NOTE:
This is a very hacky way to accomplish what you are trying to do… this can be done much cleaner like this
local main_door = script.Parent
local door_parts = {door1,door2,door3,etc} -- a list of your doors
local door_humanoid = main_door.Humanoid -- or wherever
local door_cframe = main_door.CFrame-- or main_door.PrimaryPart.CFrame, whatever you've got going on.
local function SpawnDoor()
for i=1,#door_parts do
local door_part = doors[i]
door_part.Transparency = 0
door_part.CanCollide = true -- or false, whatever you want it to be when it's alive.
end
end
local function DoorDied()
for i=1,#door_parts do
local door_part = doors[i]
door_part.Transparency = 1
door_part.CanCollide = false
end
delay(60*5, SpawnDoor) -- in 5 minutes, (60*5/60) Spawn the door.
end
door_humanoid.Died:Connect(DoorDied)
Upon alteration of the variable references at the top, this should do what you are trying to accomplish.
As personal preference, I would prefer to :Destroy() and :Clone() the door on death/spawn. However the supplied method wouldn’t hurt performance or anything, so it’s fine.