PlayerGui help!

Ok so I’m trying to set a variable for an image label, I tried, this is the code:

local imageLabel = game.Players:GetChildren().PlayerGui.MostKills.Frame.PlrImage

Ok and the error is: ServerScriptService.GameManager:56: attempt to index nil with ‘MostKills’ Which is that code above. If you see any errors please point it out. Thanks!

1 Like

That’s not how you get a player’s GUI. GetPlayers returns an array, and those array only contains the player and not their children.

If it’s a GUI, you need to do game.Players.LocalPlayer.PlayerGui in a local script.

Well this is in a server script

GetChildren, GetDescendants and GetPlayers will return an array. You need to do a local script.

1 Like

What are you trying to do with the ImageLabel?

I just want to make a variable for the imageLabel

You can’t retrieve a GUI using RemoteEvent. As I said, use a local script.

I have a script for you if you need to get all imageLabel in all players in server
for _,player in ipairs(game.Players:getChildren()) do
local imageLabel = player.PlayerGui.MostKills.Frame.PlrImage
–then type your script --it need to be a script not local script
end

So your saying, this would work on a server script?

You can access the PlayerGui through any script and anything that passes the player as an argument, LocalScripts are to be used just because they’re typically meant to be with where and how they execute.

@Kamlkaze_Kid In your previous duplicate topic, it was already made pretty clear Instance:GetChildren() can’t be used like that.

If you just need to directly index an image label, just place a LocalScript directly under it and do

 local label = script.Parent --- ????
1 Like

Yes this would work on a server script.