I'm Struggling with player.Character?

Gui button ability to copy a Character wearing morph into PlayerGui.ScreenGui.

Image



Attempt LocalScript

script.Parent.MouseButton1Click:Connect(function(player)

local player = game.Players.LocalPlayer -------

local character = player.Character

if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local element = character
if element:IsA(“Model”) then
element:Clone().Parent = player.PlayerGui.Armor.Bmorph.Suit

end

end)

OutPut

11:51:52.379 - Players.Joshua7ninjaX.PlayerGui.Armor.Bbutton.LocalScript:12: attempt to index a nil value

I Copy and paste, for player.Character script code from here
https://developer.roblox.com/en-us/api-reference/property/Player/Character

I clearly can’t found issue there?

If you don’t understand what im trying to do, please comment.

1 Like

Please read this post on how to put code in posts on the forum, as your code is hard to read without proper formatting. Inserting Code Snippets - Guide for New Members

As for the code, when getting a player’s character, try using this:

local Character = Player.Character or Player.CharacterAdded:Wait()

It appears that it is the part player.PlayerGui.Armor.Bmorph.Suit which is erroring. Are you sure the armor’s there? Are you using a local script? Does the armor get deleted by other scripts?

The character is Unarchivable meaning that it can’t be cloned nor saved in the current place Instance.
To get around this, set element’s Archivable property true before cloning it like so:

element.Archivable = true

You’re getting the error because you can’t clone it and therefore returns nil furthermore you’re doing nil.Parent

No it doesn’t get delete, if i want to add something or destroy thing like this for Example.

script.Parent.MouseButton1Click:Connect(function()

 local plr = game.Players.LocalPlayer -------

 plr.PlayerGui.Armor.Amorph.Helmet.Head1:Clone().Parent = 
 plr.PlayerGui.Armor.Pending
 wait(1) 
 plr.PlayerGui.Armor.Amorph.Helmet.Head1:Destroy()
 plr.PlayerGui.Armor.Pending.Head1.Parent = plr.PlayerGui.Armor.Bmorph.Suit
 end)
1 Like

It work for gui changing, im trying to copy Character as wearing morphs and send into PlayerGui.Armor.

Pretty sure this happens because the Archivable property of Characters is set to false. Try setting it to true before cloning.

Hey, you can’t get player from mousebutton1click, to start with

But how come this tho?

  1. local character = game.Workspace.Player – Certain player
  2. local player = game.Players:GetPlayerFromCharacter(character)

is number 2 for every Characters?

I kept getting red underline, with it.

Number 1 of course assumes you have the player, Number 2 is for if you have their character, but not the player.

I use GetPlayerFromCharacter a lot of the time for Touched events and raycasting.

script.Parent.MouseButton1Click:Connect(function()

local plr = game.Players.LocalPlayer
local character = game.Workspace.Joshua7ninjaX
local player = game.Players:GetPlayerFromCharacter(character)

character.Arm1:Clone().Parent = plr.PlayerGui.Armor.Bmorph.Suit
character.Arm2:Clone().Parent = plr.PlayerGui.Armor.Bmorph.Suit
character.Chest:Clone().Parent = plr.PlayerGui.Armor.Bmorph.Suit
character.Head1:Clone().Parent = plr.PlayerGui.Armor.Bmorph.Suit
character.Leg1:Clone().Parent = plr.PlayerGui.Armor.Bmorph.Suit
character.Leg2:Clone().Parent = plr.PlayerGui.Armor.Bmorph.Suit
character.Vehicle:Clone().Parent = plr.PlayerGui.Armor.Bmorph.Suit
print("Overwrite Scout morph")

end)

:arrow_up: This work for Only Certain Player, But it not for every Characters
do you know which object?

It’s only getting your character, well if your character is even there.
Can’t you just do:

local character = plr.Character

or

local character = workspace[plr.Name]
1 Like

Sometimes, if warranted, at the top of my localscript I do, repeat wait() until game.Players.LocalPlayer.Character . It’s not the best practice out there but, it’s worked for me in times of need.

Took me hours to get what i wanted :100:

1 Like