GetPlayerFromCharacter nil Value? [Gui Compatible?]

Im tryna achieve Gui Button is ability from Character as wearing Morph, Clone into PlayerGui. About GetPlayerFromCharacter, it work with from Touched that do something, Character(Morph) Clone into PlayerGui.

Local Script

script.Parent.MouseButton1Click:Connect(function()

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


plr.PlayerGui.UMD.WarriorM["Warrior Bot"].Arm1:Destroy()
plr.PlayerGui.UMD.WarriorM["Warrior Bot"].Arm2:Destroy()
plr.PlayerGui.UMD.WarriorM["Warrior Bot"].Head1:Destroy()
plr.PlayerGui.UMD.WarriorM["Warrior Bot"].Chest:Destroy()
plr.PlayerGui.UMD.WarriorM["Warrior Bot"].Leg1:Destroy()
plr.PlayerGui.UMD.WarriorM["Warrior Bot"].Leg2:Destroy()
plr.PlayerGui.UMD.WarriorM["Warrior Bot"].Vehicle:Destroy()
plr.PlayerGui.Message.Frame.pt1.Visible = true
wait(1)

character.Arm1.Clone().Parent = plr.PlayerGui.UMD.WarriorM["Warrior Bot"]
character.Arm2.Clone().Parent = plr.PlayerGui.UMD.WarriorM["Warrior Bot"]
character.Head1.Clone().Parent = plr.PlayerGui.UMD.WarriorM["Warrior Bot"]
character.Chest.Clone().Parent = plr.PlayerGui.UMD.WarriorM["Warrior Bot"]
character.Leg1.Clone().Parent = plr.PlayerGui.UMD.WarriorM["Warrior Bot"]
character.Leg2.Clone().Parent = plr.PlayerGui.UMD.WarriorM["Warrior Bot"]
character.Vehicle.Clone().Parent = plr.PlayerGui.UMD.WarriorM["Warrior Bot"]
print("Succesfully Added Bot")
plr.PlayerGui.Message.Frame.pt1.Visible = false
plr.PlayerGui.Message.Frame.pt2.Visible = true
wait(1)
--
plr.PlayerGui.UMD.MorphsFrame.EditClassButton.Warrior.Armor.Visible = false
plr.PlayerGui.UMD.MorphsFrame.EditClassButton.Warrior.ABack.Visible = false
plr.PlayerGui.UMD.MorphsFrame.EditClassButton.Warrior.WARight.Visible = false
plr.PlayerGui.UMD.MorphsFrame.EditClassButton.Warrior.WALeft.Visible = false
plr.PlayerGui.UMD.MorphsFrame.EditClassButton.Warrior.F.Visible = true
plr.PlayerGui.UMD.MorphsFrame.EditClassButton.Warrior.L.Visible = true
plr.PlayerGui.UMD.MorphsFrame.EditClassButton.Warrior["Warrior Bot"].Visible = true
plr.PlayerGui.Message.Frame.pt2.Visible = false
end)
Output Error

14:58:24.718 - Players.Joshua7ninjaX.PlayerGui.UMD.MorphsFrame.EditClassButton.Warrior.ABack.LocalScript:17: attempt to index local ‘character’ (a nil value)

I notice Character Archivable, set to be false and i have script that set to be true, But GetPlayerFromCharacter always allow to Clone with the Character Archivable were false, coming from Touched with Part that did.

index local ‘character’ (a nil value) Keep getting error for that, if you open Output Error

If you don’t understand, please comment.

You are using it incorrectly. GetPlayerFromCharacter needs to be used to get the player from a character model.

Instead replace your second line with:

local Character = plr.Character or plr.CharacterAdded:Wait()
2 Likes

I suggest getting the character like this:

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

So if the script loads before the character, the script will wait for the character to load first before running the rest of the code.

1 Like

Thank you, script have been solved.

1 Like

Thank you for support. MineDevs posted earlier.