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

How to clone the Player Character?

Hello guys, I want to clone the player character. So this error appears.

16:41:06.446 - Players.NiniBlackJackQc.PlayerScripts.LocalModule:50: attempt to index a nil value

Why and how to fix this?

--< Services
local PlayerService = game:GetService('Players')

--< Variables
local Player = PlayerService.LocalPlayer

Player.Character:Clone().Parent = PlayerGui.ProfileGui.ProfileFrame.Profile.Character

2 answers

✓ Accepted answer

By default, characters have their Archivable property set to false. This property determines whether an instance can be cloned, or if it can be saved. Simply set their Archivable property to true and then clone.

--< Services
local PlayerService = game:GetService('Players')

--< Variables
local Player = PlayerService.LocalPlayer

Player.Character.Archivable = true -- 
Player.Character:Clone().Parent = PlayerGui.ProfileGui.ProfileFrame.Profile.Character

The error you are experiencing is related to the character not existing at the time that the script is run. In order to fix this, simply wait for the character to appear at the beginning of the script through a repeat until loop that will repeat until the character exists.

--WAIT FOR CHARACTER
repeat wait() until game.Players.LocalPlayer.Character

--< Services
local PlayerService = game:GetService('Players')

--< Variables
local Player = PlayerService.LocalPlayer

Player.Character:Clone().Parent = PlayerGui.ProfileGui.ProfileFrame.Profile.Character

4 comments

0

I'm sorry, but I'm gonna have to downvote for suggesting looping until exists. Use events!

0

How can I use events for this? This is the only method I have ever known.

0

game.Players.LocalPlayer.CharacterAdded:Wait()

0

OK. Thanks!

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