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
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