Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cloning a player's character clientside returns nil?

i'm trying to clone the game.Players.LocalPlayer.Character to use as a viewmodel, but

local character = game.Players.LocalPlayer.Character
local viewModel = character:Clone()
viewModel.Parent = character

keeps giving me the error

attempt to index nil with 'Parent'

2 comments

1

Try waiting for the character as aviel mentioned in the answer and if that doesn't seem to work then change the archivable properties of the character

0

okay it was the archivable property that was messing everything up

1 answer

that could be because you clone the character when it didn't even load. try waiting for the character to load like this

local character = game.Players.LocalPlayer.CharacterAdded:Wait()

Edit:

local character = game.Players.LocalPlayer
character.Archivable = true
local viewModel = character:Clone()
viewModel.Parent = character

8 comments

0

if this worked mark it as answered

0

i'm not getting the error anymore but it still isn't showing up

0

it should be parented to character like you wrote in the script "viewModel.Parent = character", try looking for it under workspace.[Your name], you should find a model with your name

0

i did, still nothing

0

can you add the script i added to my answer and tell what's the output?

0

it prints my username, nil, then throws the "attempt to index nil with parent" error

0

it seems like the CharacterAdded:Wait() part is stopping the entire local script because nothing after that line from my weapon's localscript runs

0

okay i see the problem, i edited the script so it should work now

This discussion is preserved as it was. New answers, comments, and votes are closed.