Just screenshot us the whole script or create a code block, it would be very easy for us to fix it. You just showed us the output.
Well thats weird. Is it a Empty table or just nil
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
What the click, i never understood what is an “OP”. May you explain?
OP means original poster - the person who created the thread
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.
: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:
I just want to know why this is happening, am I doing something wrong?
How is PlayerGui not a valid member of Player?
GetPlayers() returns an array containing all player instances. PlayerGui is inside of a player instance not an array.
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
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.
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.