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

How to clone the Player Character?

Asked by 5 years ago

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

Log in to vote
2
Answered by 5 years ago

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

Ad
Log in to vote
-1
Answered by
y3_th 176
5 years ago

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
0
I'm sorry, but I'm gonna have to downvote for suggesting looping until exists. Use events! User#24403 69 — 5y
0
How can I use events for this? This is the only method I have ever known. y3_th 176 — 5y
0
game.Players.LocalPlayer.CharacterAdded:Wait() User#24403 69 — 5y
0
OK. Thanks! y3_th 176 — 5y

Answer this question