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

Cloning a player's character clientside returns nil?

Asked by 2 years ago

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'

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 greatneil80 2647 — 2y
0
okay it was the archivable property that was messing everything up TheDude646 72 — 2y

1 answer

Log in to vote
0
Answered by
aviel101 165
2 years ago
Edited 2 years ago

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
0
if this worked mark it as answered User#31501 0 — 2y
0
i'm not getting the error anymore but it still isn't showing up TheDude646 72 — 2y
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 aviel101 165 — 2y
0
i did, still nothing TheDude646 72 — 2y
View all comments (4 more)
0
can you add the script i added to my answer and tell what's the output? aviel101 165 — 2y
0
it prints my username, nil, then throws the "attempt to index nil with parent" error TheDude646 72 — 2y
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 TheDude646 72 — 2y
0
okay i see the problem, i edited the script so it should work now aviel101 165 — 2y
Ad

Answer this question