Zombie-ish clone game

So I’m working on this small project where when you join it makes a dummy called (player’s name)'s Clone and for some reason the ‘clone’ won’t spawn? I’m working on making the dummy have the same appearance as the player

Code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local clone = game.ServerStorage.Dummy:Clone(game.Workspace)
		clone.Name = plr.Name.."'s Clone"
		repeat 
			wait()
			clone.Humanoid:MoveTo(char:WaitForChild("HumanoidRootPart").Position)
		until game.Players.PlayerRemoving:Connect(function(plr)
			if game.Workspace:FindFirstChild(plr.Name.."'s Clone") then
				game.Workspace[plr.Name.."'s Clone"]:Destroy()
			end
		end)
	end)
end)

The clone() method doesn’t take an Instance argument like Instance.new() does; you need to do something like this:

local clone = game.ServerStorage.Dummy:Clone()
-- (some block of code goes here...)
clone.Parent = workspace

Here’s your corrected script, which I’ve also taken the time to optimize for performance:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local clone = game.ServerStorage.Dummy:Clone()
		clone.Name = plr.Name.."'s Clone"
		clone.Parent = workspace
		repeat 
			wait()
			clone.Humanoid:MoveTo(char:WaitForChild("HumanoidRootPart").Position)
		until game.Players.PlayerRemoving:Connect(function(plr)
			if game.Workspace:FindFirstChild(plr.Name.."'s Clone") then
				game.Workspace[plr.Name.."'s Clone"]:Destroy()
			end
		end)
	end)
end)

EDIT: yeah, the only optimization I could really find was changing game.Workspace to simply workspace

1 Like

The dummy probably won’t spawn because you have not parented it.

Try this

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local clone = game.ServerStorage.Dummy:Clone()
		clone.Name = plr.Name.."'s Clone"
        clone.Parent = workspace
		repeat 
			wait()
			clone.Humanoid:MoveTo(char:WaitForChild("HumanoidRootPart").Position)
		until game.Players.PlayerRemoving:Connect(function(plr)
			if game.Workspace:FindFirstChild(plr.Name.."'s Clone") then
				game.Workspace[plr.Name.."'s Clone"]:Destroy()
			end
		end)
	end)
end)
1 Like

OHHH thank you so much!!! It works now :slight_smile:
(@Ooftius yours is correct too)

Glad to help a new developer out with their projects. Hope it turns out well for you.

1 Like
local players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")
local dummy = serverStorage:WaitForChild("Dummy")

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local clone = dummy:Clone()
		clone.Parent = workspace
		clone.Name = plr.Name.."'s Clone"
		repeat 
			wait()
			clone:WaitFirstChild("Humanoid"):MoveTo(char:WaitForChild("HumanoidRootPart").Position)
		until players.PlayerRemoving:Connect(function(plr)
			if workspace:FindFirstChild(plr.Name.."'s Clone") then
				workspace[plr.Name.."'s Clone"]:Destroy()
			end
		end)
	end)
end)
1 Like