Big Delay before Dummy Respawns

Ello.

I made a dummy that when killed, respawns in the same place. When I kill it, the script does its job, but there’s like a 1-2 minute delay before it actually respawns.

Here’s the script:

--// VARIABLES //--
local ServerStorage = game:GetService("ServerStorage")

local dummy = script.Parent
local hum = dummy:WaitForChild("Humanoid")

--// MY FUNCTIONS //--
local function dummyDeath()
	if not workspace:FindFirstChild("NewMilkMan") then
		task.wait(2)
		
		for _, parts in pairs(dummy:GetChildren()) do
			if parts:IsA("BasePart") then
				game:GetService("Debris"):AddItem(parts, 0)
			end
		end
		
		task.wait(1)
		
		local newDummy = ServerStorage:FindFirstChild("NewMilkMan"):Clone()
		newDummy.Name = "Milk Man!!"
		newDummy.Parent = workspace
		
		dummy:Destroy()
	end
end

--// MAIN SCRIPT //--
hum.Died:Connect(dummyDeath)

Idk how to fix this

2 Likes

There 2 reasons I believe the script isn’t working as intended:

Problem 1

The problem is most likely coming from the .Died event in your main script. This event doesn’t immediately fire when the health of the NPC hits 0, it fires after the death process is finished, which includes physics, breaking joints, and animations.

A more reliable method would be using .HealthChanged instead, which fires every time the NPC is damaged.

Problem 2

At the beginning of the dummyDeath function, you are checking if the NewMilkMan instance is not in the workspace, but this won’t work right for 2 reasons: 1. The name of the dummy is being changed to Milk Man!! when you are checking for NewMilkMan and 2. You are not destroying the dummy until after the check runs, which means this check will never pass. It’s best to just remove this line.

View Updated Script

I added a debounce (db) variable to ensure that the dummyDeath function doesn’t fire multiple times.

--// VARIABLES //--
local ServerStorage = game:GetService("ServerStorage")

local dummy = script.Parent
local hum = dummy:WaitForChild("Humanoid")
local db = true

--// MY FUNCTIONS //--
local function dummyDeath()
	task.wait(2)
	
	for _, parts in pairs(dummy:GetChildren()) do
		if parts:IsA("BasePart") then
			game:GetService("Debris"):AddItem(parts, 0)
		end
	end
	
	task.wait(1)
	
	local newDummy = ServerStorage:FindFirstChild("NewMilkMan"):Clone()
	newDummy.Name = "Milk Man!!"
	newDummy.Parent = workspace
	
	dummy:Destroy()
end

--// MAIN SCRIPT //--
hum.HealthChanged:Connect(function(health)
	if health <= 0 and db then
		db = false
		dummyDeath()
	end
end)

I’m not sure if this will solve the delay problem, but it should be a better version. If the delay problem persists, I’m not sure what would fix it.

1 Like

It works, but the delay is still present.

1 Like
task.wait(2)

local ServerStorage = game:GetService("ServerStorage")
local hum = script.Parent:WaitForChild("Humanoid")
local Debris = game:GetService("Debris")

hum.Died:Connect(function()
	local dummy = hum.Parent

	local newDummy = ServerStorage.NewMilkMan:Clone()
	newDummy.Name = "Milk Man!!"

	--task.delay(1, function() --fine tuning if needed
		newDummy.Parent = workspace
	--end)

	Debris:AddItem(dummy, 0)
end)

Should end up on the next update as is, instant spawn like.

try to execute this maybe it fixed using this one

Code:

–// VARIABLES //–
local ServerStorage = game:GetService(“ServerStorage”)
local Debris = game:GetService(“Debris”)

local dummy = script.Parent
local hum = dummy:WaitForChild(“Humanoid”)

– Store the position where the dummy started so it respawns in the same spot
local spawnLocation = dummy:GetPrimaryPartCFrame()

–// MY FUNCTIONS //–
local function dummyDeath()
– 1. Check if the template exists in ServerStorage first
local template = ServerStorage:FindFirstChild(“NewMilkMan”)

if template then
	-- 2. Short delay for the 'death' animation/effect (adjustable)
	task.wait(2)
	
	-- 3. Clone and position the new dummy BEFORE destroying the old one
	-- This prevents the "delay" feel of waiting for the engine to clean up
	local newDummy = template:Clone()
	newDummy.Name = "Milk Man!!"
	newDummy:SetPrimaryPartCFrame(spawnLocation)
	newDummy.Parent = workspace
	
	-- 4. Clean up the old dummy immediately
	dummy:Destroy()
else
	warn("Could not find 'NewMilkMan' in ServerStorage!")
end

end

–// MAIN SCRIPT //–
hum.Died:Connect(dummyDeath)

1 Like

I had to edit it a little bit, but it works! Thanks. I appreciate the help from all of you guys

1 Like

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