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

I need a way to clone a character of a player help please?

So, I am working on a game and I am getting an error for cloning the character, it says its a nil value. Please help

game.Players.PlayerAdded:connect(function(p)
	wait(7)
	local c = p.Character
	if c ~= nil then
		c = c:Clone()
	else
		error("Not Working")
	end
	c.Parent = workspace
	c.Name = ""
	c.HumanoidRootPart.CFrame = CFrame.new(workspace.Points.Spawn.Position)
	local humanoid = c:WaitForChild("Humanoid")
	wait(2)
	humanoid:MoveTo(Vector3.new(-46.5, 5.85, 100))
	wait(1.08)
	humanoid:MoveTo(Vector3.new(-5.5, 5.85, 100))
	wait(2.30)
	wait(5)
	humanoid:MoveTo(Vector3.new(-46.5, 5.85, 100))
	wait(2.30)
	humanoid:MoveTo(Vector3.new(-46, 5.85, 117.5))
end)

This is the error I'm getting:

21:12:46.194 - Workspace.Script:9: attempt to index local 'c' (a nil value)

1 comment

0

I actually just answered a question that (I think) has the exact same issue you do: https://scriptinghelpers.org/questions/56553/#55261

2 answers

✓ Accepted answer

Use GetService and DO NOT USE connect ITS DEPRECATED.

It also errors because there was no CharacterAdded event. Also it errors because the Name cannot be set to nothing (""). If you would like for the name to not be visible, instead change their DisplayDistanceType in the Humanoid. This is only for the cloning of the character.

game:GetService("Players").PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(c)
        c.Archivable = true -- If this is true you can clone it. Else if it's false you can't.
        local clone = c:Clone() -- Make Archivable true FIRST. then clone it.
        clone.Parent = game.Workspace
        clone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
    end)
end)

2 comments

0

I use :connect and game.Players all the time, while it is deprecated, I really don't think roblox is going to remove it's funcionality, oh so many things would break. I also doubt they will completely remove Workspace because of the same thing, so many old games would be utterly broken.

0

This is a better answer, as instead of using wait(7), incapaz uses p.CharacterAdded:Connect(function(c) instead. Good work.

Try this;

game.Players.PlayerAdded:connect(function(p)
    wait(7)
    local c = p.Character
    c.Archivable = true
    if c ~= nil then
        c = c:Clone()
    else
        error("Not Working")
    end
    c.Parent = workspace
    c.Name = ""
    c.HumanoidRootPart.CFrame = CFrame.new(workspace.Points.Spawn.Position)
    local humanoid = c:WaitForChild("Humanoid")
    wait(2)
    humanoid:MoveTo(Vector3.new(-46.5, 5.85, 100))
    wait(1.08)
    humanoid:MoveTo(Vector3.new(-5.5, 5.85, 100))
    wait(2.30)
    wait(5)
    humanoid:MoveTo(Vector3.new(-46.5, 5.85, 100))
    wait(2.30)
    humanoid:MoveTo(Vector3.new(-46, 5.85, 117.5))
end)

https://scriptinghelpers.org/questions/233/how-do-you-clone-someones-character

With a quick Google search I found nate890 's answer, where he said you need to turn on Archivable, which seemed to have worked.

3 comments

0

That didn't work for me

0

I don't think you can clone a nil value.

0

(I don't know if it alerts you when edits are made so I'm commenting to say look at my answer again)

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