#Why is this nil

1 messages · Page 1 of 1 (latest)

viral thicket
#
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local ViewportFrame = script.Parent

local char = player.Character or player.CharacterAdded:Wait()

repeat wait() until player.Character

print(char)
local charC = char:Clone()
print(charC)

charC.Parent = ViewportFrame
charC:PivotTo(CFrame.new(Vector3.new(0,0,0)))
#

why is charC nil

#

even tho char is not

dusky steppe
#

you're doing it in a server script

#

nvm

#

that's cus u print it before the charC is assigned a parent

viral thicket
potent girderBOT
#

studio** You are now Level 11! **studio

dusky steppe
dusky steppe
#

weird

turbid coyote
#

Check the player model. If the Archivable property is set to false, it cannot be cloned.

dusky steppe
#

oh right, the character is unarchivable at first

austere gull
# viral thicket ```lua local Players = game:GetService("Players") local player = Players.LocalPl...
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local ViewportFrame = script.Parent

local char = player.Character or player.CharacterAdded:Wait()

- repeat wait() until player.Character

- print(char)
+ char.Archivable = true;
local charC = char:Clone()
+ char.Archivable = false;
- print(charC)

charC.Parent = ViewportFrame
charC:PivotTo(CFrame.new(Vector3.new(0,0,0)))
#

By default Player Characters .Archivable property is set to false, meaning when you clone it, it doesn't actually clone

#

Thus, setting it to true before cloning it will allow you to do so, and you can thereafter set Archivable back to false if you wish.

#

You also don't need the repeat wait() until player.Character segment, as this code is redundant since the player.CharacterAdded:Wait() await is sufficient. Essentially what your local char = player.Character or player.CharacterAdded:Wait() assignment is doing is setting local char equal to player.Character, and if the result is nil then we fallback to or, whereby we await the player.CharacterAdded event by using player.CharactedAdded:Wait()