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)
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)
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.