PlayerGui return as nil

I am making a 2D game on Roblox and I want other players to show up on your screen as ImageLabels. I made a script where it goes into the said players Gui take the image of their character and placed it in the clone in your Gui but the PlayerGui of that player keeps returning as nil. I’ve tried to Use WaitForChild, FindFirstChild and repeat until but it doesn’t seem to fix the problem. I’m currently looking for another solution to fix this problem, any help is appreciated!

1 Like

Could you please show your code so we as community can look into it? :happy1:

image Ok so the ImageLabel that is cloned has on ObjectValue which is named refer so the cloned ImageLabel can copy the players character image and position by using the object value as a reference. The only problem is the PlayerGui is returning as nil for some reason.

So you are making a custom player list basically?

Yeah, But I’m trying to get the PlayerGui from each player.

Why are you trying to get PlayerGui though? I just don’t understand what you doing exactly…

Ok so a imagelabel is placed inside of a ScreenGui in the PlayersGui, The script goes and try to get the imagelabel from each of the players.
image

That PlayerGuis of other players are not accessible in a LocalScript. Only the current player’s PlayerGui is not nil.

So I wonder If the problem comes from line 6

because when I tested this I got the error
“[The current identity (2) cannot Class security check (lacking permission 6)]”

also if your going through the players, why not use
game.Players:GetPlayers()
also what kind of script is it

Its a Normal script not local nor module

Server scripts cannot access the PlayerGui of any players. Only LocalScripts of the LocalPlayer can use the PlayerGui.

Alright, Then im still getting the identity error with the :IsA(“Player”) part which may be a problem

I see. I’ll use a localscript to test it

You will need to replicate the player data to every player using a RemoteEvent or some other method. There is no way for one script to have access to all of the PlayerGuis. I would recommend having a RemoteEvent that every player listens to the server fires an event to every time a player moves. I would have it contain where the player is moving and when they started and you can tween the movement on each client.

Is this confirmed anywhere? Unless I’m missing something, I can in fact access PlayerGui on a server script in Studio.

You will be using remote events to access the players gui since Server scripts arent able to access the players playergui , you will use a server script to fire a remote event which the localscript detects and then finds the players gui.

Well actually a server script can get the playergui, im not really sure what it would be useful for, but if you wanted to make a list of player guis, you could

local guis = {}
game.Players.PlayerAdded:Connect(function()
guis = {}
for i, player in pairs(game.Players:GetPlayers())do
table.insert(guis,#guis+1,player.PlayerGui)
end
end)

-- to test 

wait(10)
print(guis[1].Parent.Name)

-- output would be 
-- username (of the player which the PlayerGui was from)

this would in a table have all the playerguis, and would reset the table everytime someone was added

Yes I understand that, and using this method should work for you. What I’m curious about is why accessing PlayerGui from the server does not work. It seems to work for me in Studio.

I think it’s because UI is client sided (or supposed to be).

Without Experimental Mode, the player’s GUI is not visible to the server. Also, changing what’s shown in a player interface should generally be managed by the client itself.

https://developer.roblox.com/en-us/articles/Converting-From-Experimental-Mode

1 Like