Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
uhTeddy 101
6 years ago

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)

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

2 answers

Log in to vote
1
Answered by 6 years ago

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)
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. theCJarmy7 1293 — 6y
0
This is a better answer, as instead of using wait(7), incapaz uses p.CharacterAdded:Connect(function(c) instead. Good work. T0XN 276 — 6y
Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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.

0
That didn't work for me uhTeddy 101 — 6y
0
I don't think you can clone a nil value. ILikeTofuuJoe 1 — 6y
0
(I don't know if it alerts you when edits are made so I'm commenting to say look at my answer again) User#1007 6 — 6y

Answer this question