#player.character returning nil

1 messages · Page 1 of 1 (latest)

rose lichen
#
local Players = game:GetService("Players")
local player = Players.LocalPlayer

-- Wait until the character fully loads and has a HumanoidRootPart
local function waitForCharacterWithRoot()
    local character = player.Character or player.CharacterAdded:Wait()
    while not (character and character:IsA("Model") and character:FindFirstChild("HumanoidRootPart")) do
        task.wait()
    end
    return character
end

-- Wait for GUI to be ready
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local viewport = screenGui:WaitForChild("ViewportFrame")

-- Remove old model from viewport
local oldModel = viewport:FindFirstChildOfClass("Model")
if oldModel then
    oldModel:Destroy()
end

-- Load character safely
local character = waitForCharacterWithRoot()
print("Character loaded:", character)

-- Clone character
local clonedChar = character:Clone()
if not clonedChar or not clonedChar:IsA("Model") then
    warn("Cloning failed.")
    return
end

-- Set PrimaryPart if needed
local root = clonedChar:FindFirstChild("HumanoidRootPart")
if not root then
    warn("Cloned character missing HumanoidRootPart.")
    return
end

clonedChar.PrimaryPart = root
clonedChar.Parent = viewport

-- Setup a camera
local camera = Instance.new("Camera")
camera.CFrame = CFrame.new(Vector3.new(0, 2.5, 6), Vector3.new(0, 2.5, 0))
viewport.CurrentCamera = camera
camera.Parent = viewport
#

little test script i made in a brand new studio

#

idk if im just dumb or something but PLAYER.CHARACTER IS NIL???

#

i dont know how to get the message with the colors

main wing
rose lichen
#

AM I DUMB

#

WHAT AM I MISSING

#

ya know what ill make a brand new script

#
local character = player.Character or player.CharacterAdded:Wait()

local charclone = character:Clone()
charclone.Parent = game.Workspace
#

brand new script i made

#

and THIS game ne an erro

#

error

#

attempt to index nil with parent

#

what am i doing brong broooooo

ruby light
#

Archivable?

rose lichen
#

i swear if thats the problem

main wing
rose lichen
#

then im gonna explode

idle lance
#

is this a localscript

#

or Script

rose lichen
#

ive been trying to fix this on my own for like 2-3 hours

#

local script

idle lance
#

hmmm

#
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

if character then
    local charclone = character:Clone()
    charclone.Parent = game.Workspace
else
    warn("Character is nil!")
end
#

try this

rose lichen
#

warns character is nil

#

wait

ruby light
rose lichen
#

doesnt even get to the warn part

#

it gives me attempt to index nil witth parent

#

ima try changing the archivable

main wing
#

or just remove player.CharacterAdded:Wait() and just keep player.Character

rose lichen
#

ohmygod

#

it was the archivable

#

it works now

#

no way it was that simple

main wing
#

ok

ruby light
#

💀💀💀

main wing
#

3 hours lmao

rose lichen
#

i just wasted hours of my life

#

im gonna go cry in a ball now