Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My code is supposed to clone characters, but instead errors! Help?

So I'm trying to make a zombie script where anyone that dies gets infected. In order to do this, I need to clone the player but I get this error message saying;

16:38:33.643 - Workspace.Arcerion.zombify:5: attempt to index local 'zombie' (a nil value)

So the issue with this, I assume is because Roblox doesn't allow cloning a player's character, but I've seen people do it before. Now I could always create a npc that transforms into the character, but I know that there's another way to do this.

Here is the code I've sent, it's really simple because let's be honest when I script and run into an issue I want to solve it before continuing. I just can't resolve this issue, so I'm asking for help.

Code;

local character = script.Parent

local zombie = character:clone()

zombie.Parent = workspace

local rooty = character:FindFirstChild("HumanoidRootPart")


if rooty ~= nil then

	zombie:MoveTo(rooty.Position)

end

3 comments

0

Also this script goes into the character, then is supposedly supposed to clone the character. That's why character = script.Parent so keep that in mind.

0

clone is deprecated, use Clone

0

Yes, but that still doesn't resolve this issue. Thanks though!

1 answer

✓ Accepted answer

By doing some reading of your code, I got your solution. The issue of your code is that you did not enable Archivable which is a property of the characters model. So if you do:

local character = script.Parent

character.Archivable = true

local zombie = character:Clone()

character.Archivable = false

zombie.Parent = workspace

local rooty = character:FindFirstChild("HumanoidRootPart")


if rooty ~= nil then

    zombie:MoveTo(rooty.Position)

end

That should do it, let me know if you have anymore issues!

2 comments

0

So when you enable "Archivable" it allows it to be cloned? I'll give that a try, and if it works I got myself an answer!

0

Thanks! I appreciate your help, and if there's any you need don't mind contacting me, I'll probably add you on Roblox as well!

This discussion is preserved as it was. New answers, comments, and votes are closed.