so I’m making a script where when the npc dies I want jump = true but for some reason there is a slight delay at the time of the jump so after dying the npc does not jump immediately but there is a delay of a few seconds then jump.
local Copy = script.Parent.Parent:Clone()
local NPC = script.Parent.Parent
for i,v in pairs(NPC:GetChildren()) do
if v:IsA('Humanoid') then
Humanoid = v
end
end
if Humanoid then
Humanoid.Died:Connect(function()
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
wait(3.5)
Copy.Parent = NPC.Parent
Copy:MakeJoints()
NPC:Destroy()
end)
else
warn('Cannot find Humanoid in Respawn Script!')
end
I believe the problem is that the .Died event is slightly delayed and doesn’t fire immediately. However, I found a better way to instantly tell when the NPC is dead. When the health property is updated, you can connect a function to check if the health value is 0 (which means the NPC is dead). Then you can make the NPC jump without any delay. I tested the script myself, and it works perfectly.
Here is the modified script I made for you:
local Copy = script.Parent.Parent:Clone()
local NPC = script.Parent.Parent
for i,v in pairs(NPC:GetChildren()) do
if v:IsA('Humanoid') then
Humanoid = v
end
end
if Humanoid then
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if Humanoid.Health == 0 then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
wait(3.5)
Copy.Parent = NPC.Parent
Copy:MakeJoints()
NPC:Destroy()
end
end)
else
warn('Cannot find Humanoid in Respawn Script!')
end