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

Why is the clone of the character nil?

Asked by 3 years ago

Here's my code in a server script:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    local char = player.Character or player.CharacterAdded:Wait()
    local clone = char:Clone()
    local root = clone:WaitForChild("HumanoidRootPart")
    local char1 = workspace:WaitForChild("char1")
    root.CFrame = char1:WaitForChild("HumanoidRootPart").CFrame
end)

I've tried so many things that I just cannot remember anything I've tried. Here's the error that pops up: ServerScriptService.Script:6: attempt to index nil with 'WaitForChild'. Apologies if this is a stupid question, this has just been bothering me so much.

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Player Character models are not archivable by default; if you set it so they are, then it would not be nil.

Here is a script you can put in the workspace that will make characters archivable by default

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
plr.Character.Archivable = true
end)
end)
0
Ah! I didn't know this. Thanks! User#41156 0 — 3y
Ad

Answer this question