"PlayerGui is not a valid member of Player"

Just nil.

30 charssssssssssssss

@OP you still haven’t shown us your code. I’d suggest you use a codeblock to post the code, rather than a screenshot

4 Likes

What the click, i never understood what is an “OP”. May you explain?

OP means original poster - the person who created the thread

3 Likes

Actually when I try to get the contents of the players by using :GetChildren() on the players themselves in a for i, v loop it just gives me a memory of a table e.g:

table: 0x3cb32bc62x12

I know that my code is not the problem but it is probably the WAY i’m trying to get the players…

All i’m using is:

wait(25)
for i, player in pairs(game.Players:GetPlayers()) do
	local playerchildren = player:GetChildren()
	wait(5)
	print(playerchildren)
end

Don’t mind the 25 wait at the start it’s just to make sure that the players load fully into the game because i’m using a test server not just studio directly to make sure that everything will work in the real game not just in studio, however I don’t know why it gives me a memory of a table… but is the way i’m trying to get the players correct?

This is starting to confuse me as to why this is happening.

EDIT1: When I try printing the name or the value of playerchildren it just gives me nil.

EDIT2: For anyone whose curious when I print player it will give me the name of the players just fine.

1 Like

:GetChildren() gets all the childrens of an instance, i think you should make an other for loop, to then print the name:

game.Players.PlayerAdded:Connect(function(plr)
    for _, plrchild in pairs(plr:GetChildren()) do
        print(plrchild)
    end
end)

You are correct, now it prints the children of the players correctly but that still doesn’t explain why PlayerGui would be returned as nil?

I still need an answer for that question.

Thats a little wrong, you could just have done what you done, but like this:

wait(25)
for _, player in pairs(game.Players:GetChildren()) do
    print(player:WaitForChild("PlayerGui"))
end

Try using this code to see if it works.

I specificed the PlayerGui by a .

Just like this:

game.Players:GetPlayers().PlayerGui

Now if I were to try my method it would give me this error:

playergui

I just want to know why this is happening, am I doing something wrong?

How is PlayerGui not a valid member of Player?

1 Like

GetPlayers() returns an array containing all player instances. PlayerGui is inside of a player instance not an array.

1 Like

So how would I fix this problem if that’s the case?

PlayerGui is a valid member of Player.

I guess i can’t explain…

Just try using this code then!

game.Players.PlayerAdded:Connect(function(plr)
    print(plr:WaitForChild("PlayerGui"))
end)

Also, waiting 25 seconds is a little vague, just use PlayerAdded.

If you want to get the PlayerGui of all the players in game. You can loop through an array containing all the players.

for _,Player in pairs(game:GetService(“Players”):GetPlayers()) do
      local PlayerGui = Player:WaitForChild(“PlayerGui”)
      print(#PlayerGui:GetChildren()) — Prints the number of children in the PlayerGui. 
end
1 Like

It’s still giving me the same error, it doesn’t recongize PlayerGui…

DUDE, we just gave you the code!! Use what we done!

Strange, I have tried your method that you posted before you deleted your post and it printed PlayerGui just fine, not sure what’s the problem here but I will try and fix it by myself.

The code that you gave me was:

wait(25)
for i, player in ipairs(game.Players:GetPlayers()) do
	wait(5)
	print(player.PlayerGui)
end

It didn’t give me nil this time.

1 Like

What are you trying to do as it seems like there could better way of achieving what you are trying to do? It is also worth mentioning I wasn’t able to reproduce the error from your first post with the code you provided. Please could you provide the exact code and hierarchy where the error is coming from.

:GetChildren() returns an array of the children of the object you are calling :GetChildren() on so when you print it, it prints the memory code of the table. To reference the table :GetChilren() returns you could either directly reference a child by:

local Folder = workspace.Folder:GetChildren()
print(Folder.SomeObject.Name)

or use a for loop to loop through the array GetChildren() returns and reference each child in turn:

local Folder = workspace.Folder

for _, Child in ipairs(Folder:GetChildren()) do
	print(Child.Name) -- Prints each childs name in turn
end

When using :GetPlayers() in a for loop you should always use ipairs over pairs as :GetPlayers() returns an array and ipairs is quicker in this situation:

local PlayersService = game:GetService("Players")

for _, Player in ipairs(PlayersService:GetPlayers()) do
	-- Do something
end

As a possible fix you could directly reference the PlayerGui from the player returned from GetPlayers():

wait(25)
for i, player in ipairs(game.Players:GetPlayers()) do
	wait(5)
	print(player.PlayerGui)
end

The server can see the players Gui’s but any changes made from the client wont replicate to the server so the server will never see an updated version of the players Gui’s. When the player joins the game the players Gui’s are replicate from StarterGui and placed into PlayerGui under the player.

1 Like

Alright so I have come to a conclusion that since your script which finds the PlayerGui works fine then it’s a problem from one of my many scripts that I am trying to change the GUIs with.

And I can confirm this because when I tried to do the exact same thing in an another baseplate that I created trying to change stuff with PlayerGui but in a different way it works, thank you for the long answer anyways you explained how this works very well!

It might have something to do with one of my plugins that I use to edit the GUIs or something, but outside of what i’m currently trying to do I can change GUIs using PlayerGui just fine, something might have glitched or something, I will just remake what I did so it can work.

UPDATE: I fixed the problem by simply getting the PlayerGui in the client and not in the server like this:

local playerGui = game.Players.LocalPlayer.PlayerGui

I didn’t have to use :WaitForChild() or anything.

And if I wanted to update it to everyone I will have to use a Remote Event then when the function fires get your Remote Event and just send a request to the server by inserting a Local Script into StarterGui and use :FireServer then insert a Script into ServerScriptService and use .OnServerEvent and then use :FireAllClients() inside it and in an another Local Script inside StarterGui just use .OnClientEvent and tell the game what you want to change about the GUIs from there.

I am writing all of this information so the people who have this problem and go search it in the dev forums to see if there’s a solution to the problem would find this and then easily fix it.

It wasn’t my scripts or plugins doing this but it was the HOW i’m trying to get PlayerGui and it was from the server I simply fixed all of this by getting the PlayerGui from the client like I said.

6 Likes