Dummy respawn system not working

so i’ve made a dummy repsawn system that just wont work properly maybe im just stupid yk but yeah

ive made it work before but that was only with one dummy and now its either no respawning or 3 respawnings at the spawn instead of one

and yeah i tried something a bit weird or idk if it is actually im practically i moron rn

where i used this elseif v.spawn.Value == 3 then line thing multiple times which also didnt work yeaah help me pls i beg

help is very appreciated, thanks ahead

local ds = game:GetService("Debris")
local dummy = game.ServerStorage:WaitForChild("Weakest Dummy")
local folder = game.Workspace.dummys

local dummySpawns = {
	spawn1 = folder.spawns.dummyspawn1,
	spawn2 = folder.spawns.dummyspawn2,
	spawn3 = folder.spawns.dummyspawn3
}

function Dummy()
	for i,v in pairs(folder:GetChildren()) do
		if v.Name == "Weakest Dummy" then
			v.Humanoid.Died:Connect(function()
				if v.spawn.Value == 1 then
					local clone = dummy:Clone()
					clone.spawn.Value = v.spawn.Value
					clone:PivotTo(dummySpawns.spawn1.CFrame)
					clone.Parent = folder
					ds:AddItem(v, 3)
					Dummy()
				elseif v.spawn.Value == 2 then
					local clone = dummy:Clone()
					clone.spawn.Value = v.spawn.Value
					clone:PivotTo(dummySpawns.spawn2.CFrame)
					clone.Parent = folder
					ds:AddItem(v, 3)
					Dummy()
				elseif v.spawn.Value == 3 then
					local clone = dummy:Clone()
					clone.spawn.Value = v.spawn.Value
					clone:PivotTo(dummySpawns.spawn3.CFrame)
					clone.Parent = folder
					ds:AddItem(v, 3)
					Dummy()
				end
			end)
		end
	end
end

Dummy()
3 Likes

The recursive call to Dummy() within the Died event handler is likely causing the issue. Each time a dummy dies, Dummy() is called again, creating additional connections to the Died event of all dummies, here’s an improvised script:

local ds = game:GetService("Debris")
local dummyTemplate = game.ServerStorage:WaitForChild("Weakest Dummy")
local folder = game.Workspace.dummys

local dummySpawns = {
	spawn1 = folder.spawns.dummyspawn1,
	spawn2 = folder.spawns.dummyspawn2,
	spawn3 = folder.spawns.dummyspawn3
}

local function respawnDummy(originalDummy)
	local spawnPoint = dummySpawns["spawn" .. originalDummy.spawn.Value]
	if spawnPoint then
		local clone = dummyTemplate:Clone()
		clone.spawn.Value = originalDummy.spawn.Value
		clone:PivotTo(spawnPoint.CFrame)
		clone.Parent = folder
		-- Connect Died event for new clone
		clone.Humanoid.Died:Connect(function() 
			respawnDummy(clone)
		end)
		ds:AddItem(originalDummy, 3)  -- Clean up old dummy
	end
end

-- Set up initial connections
for _, v in pairs(folder:GetChildren()) do
	if v:IsA("Model") and v.Name == "Weakest Dummy" then
		v.Humanoid.Died:Connect(function() 
			respawnDummy(v)
		end)
	end
end

now this happens which has happened before for me

Oh wow, I will test it out quick.

Im not sure but you might have to clone the dummy BEFORE it is dead because when it died its joints break and it makes it unusable so try to clone it before and when it dies you can parent that clone to workspace

im cloning the template in serverstorage so the joints should be fine

For it to not spawn 3 dummies for example i think you have to add a debounce as you call the function in itself which then replicates the process od the dummy cloning. So just add a debounce of like 3 seconds.

1 Like

this dosent work either.

either im bad or studio hates me

local ds = game:GetService("Debris")
local dummy1 = game.ServerStorage.dummys:WaitForChild("Weakest Dummy1")
local dummy2 = game.ServerStorage.dummys:WaitForChild("Weakest Dummy2")
local dummy3 = game.ServerStorage.dummys:WaitForChild("Weakest Dummy3")
local folder = game.Workspace.dummys

local dummySpawns = {
	spawn1 = folder.spawns.dummyspawn1,
	spawn2 = folder.spawns.dummyspawn2,
	spawn3 = folder.spawns.dummyspawn3
}

local cooldown = false

function Dummy()
	for i,v in pairs(folder:GetChildren()) do
		if cooldown then
			repeat
				wait(1)
				Dummy()
			until cooldown == false
		end
		
		if v.Name == "Weakest Dummy" then
			if not cooldown then
				v.Humanoid.Died:Connect(function()
					cooldown = true
					local clone = dummy1:Clone()
					clone:PivotTo(dummySpawns.spawn1.CFrame)
					clone.Parent = folder
					ds:AddItem(v, 3)
					wait(3)
					cooldown = false
					Dummy()
				end)
			elseif v.Name == "Weakest Dummy2" then
				if not cooldown then
					v.Humanoid.Died:Connect(function()
						cooldown = true
						local clone = dummy2:Clone()
						clone:PivotTo(dummySpawns.spawn2.CFrame)
						clone.Parent = folder
						ds:AddItem(v, 3)
						wait(3)
						cooldown = false
						Dummy()
					end)
				end
			end
		elseif v.Name == "Weakest Dummy3" then
			if not cooldown then
				v.Humanoid.Died:Connect(function()
					cooldown = true
					local clone = dummy3:Clone()
					clone:PivotTo(dummySpawns.spawn3.CFrame)
					clone.Parent = folder
					ds:AddItem(v, 3)
					wait(3)
					cooldown = false
					Dummy()
				end)
			end
		end
	end
end

Dummy()

ahhh i see every time it respawns it runs the dummy again but because its still registered dead the dummy then it will clone again and again before it gets removed

edit: still dont know how to fix but trying

You’re adding a ton of connections every cycle through. Make a new function that respawns the dummy.

Code:

local ds = game:GetService("Debris")
local dummy = game.ServerStorage:WaitForChild("Weakest Dummy")
local folder = workspace.dummys
local dummySpawns = folder.spawns

local function OnDummyDeath(v)
	local clone = dummy:Clone()
	clone.spawn.Value = v.spawn.Value
	clone:PivotTo(dummySpawns["dummyspawn".. v.spawn.Value].CFrame)
	clone.Parent = workspace

	ds:AddItem(v, 3)
end

folder.ChildAdded:Connect(function(v)
	if v.Name == "Weakest Dummy" then
		v.Humanoid.Died:Connect(function()
			OnDummyDeath(v)
		end)
	end
end)

for i, v in pairs(folder:GetChildren()) do
	if v.Name == "Weakest Dummy" then
		v.Humanoid.Died:Connect(function()
			OnDummyDeath(v)
		end)
	end
end

9:attempt to index nil with ‘spawn’

Fixed, I forgot to send over the dummy in the function. Try my edited code.

sorry i havent been responding its because of christmas eve and stuff but i will try it now

1 Like

there arent any errors in console but this happens

i found a solution here is my code if anyone wants it

-- < Services > --
local ds = game:GetService("Debris")
local ss = game:GetService("ServerStorage")
local ws = game:GetService("Workspace")

-- < Folders > --
local dummysFolder = ws:WaitForChild("map"):WaitForChild("dummys")
local dummyStorage = ss:WaitForChild("dummys")

-- < References > --
local dummy = dummyStorage:WaitForChild("Weakest Dummy")
local dummySpawns = dummysFolder.spawns

-- < Function to handle dummy death > --
local function OnDummyDeath(v)
	local clone = dummy:Clone()
	clone:WaitForChild("spawn").Value = v:WaitForChild("spawn").Value
	local spawnLocation = dummySpawns["spawn".. clone:WaitForChild("spawn").Value]

	if spawnLocation then
		clone.HumanoidRootPart.CFrame = spawnLocation.CFrame
		ds:AddItem(v, 3)
		wait(3)
		clone.Parent = dummysFolder
	else
		warn("Spawn location not found for spawn".. clone:WaitForChild("spawn").Value)
		clone:Destroy()
	end
end

-- < When a dummy is added > --
local function OnDummyAdded(v)
	if v.Name == "Weakest Dummy" then
		v.Humanoid.Died:Connect(function()
			OnDummyDeath(v)
		end)
	end
end

-- < Registering all dummys on game start > --
local function RegisterDummys()
	for _, v in pairs(dummysFolder:GetChildren()) do
		OnDummyAdded(v)
	end
end

dummysFolder.ChildAdded:Connect(OnDummyAdded)
RegisterDummys()

Its located in serverscriptservice

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