Gui Button Script, Move and Destroy

Im tryna work on Gui button script, ability to move ‘Model’ different steps [PlayerGui.ScreenGui and etc].

Summary my issue i’ve capture :arrow_down:

Script

script.Parent.MouseButton1Click:Connect(function()
local plr = game.Players:GetChildren()
plr.PlayerGui.Armor.Amorph.Helmet.Head1.Parent = plr.PlayerGui.Armor.Pending

plr.PlayerGui.Armor.Amorph.Helmet.Head1:Destroy()

plr.PlayerGui.Armor.Pending.Head1.Parent = plr.PlayerGui.Armor.Bmorph.Suit
end)

Image

Output

05:14:10.769 - Players.Joshua7ninjaX.PlayerGui.Armor.Abutton.SyncingMorph:3: attempt to index field ‘PlayerGui’ (a nil value)

I don’t see anything wrong with my scripting, Index field value (‘PlayerGui’), because i did add local plr = game.Players:GetChildren()

I also search what ‘index field’ Class Index
PlayerGui is relevant to Class Index?

You defined plr as a table, local plr = game.Players:GetChildren(), it is a table of all the players in the game. PlayerGui is not a valid index(reference) of a table of players, if this is in a local script ( as it usually should be when using Mouse inputs) and if you are trying to get the local player then use game.Players.LocalPlayer. So a re-wrote version of your script:

script.Parent.MouseButton1Click:Connect(function()

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

        plr.PlayerGui.Armor.Amorph.Helmet.Head1.Parent = plr.PlayerGui.Armor.Pending

     plr.PlayerGui.Armor.Amorph.Helmet.Head1:Destroy()

   plr.PlayerGui.Armor.Pending.Head1.Parent = plr.PlayerGui.Armor.Bmorph.Suit
end)

As a side note if you needed to get a table of players in the game, there is a built in function for it:


1 Like

Thank you :100:

It work, it did what i wanted :100: