Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Get PlayerGUI from Server Side Script?

I've created an empty array. And when a player joins I add the player to the array on the onPlayerAdded function. This function then calls another function which is called after the player has been added to the Array.

This function goes through the array and for each player it does something.

I want this function to enable a TextBox from each players PlayerGui that is currently in the Array.

Due to the fact that the player's name is in a variable when I include that variable inside of the function it takes it as a property and throws the error. "PlayerName is not a valid member of Players".

local PlayerService = game:GetService("Players")
local InLobby = {}

function onPlayerAdded(player)
	table.insert(InLobby, player)
	DebugInLobby()
end

function DebugInLobby()
	for i, InLobbyPlayer in ipairs(InLobby) do
		local playerName = InLobbyPlayer.Name
		local playerGui = game.Players.playerName:WaitForChild("PlayerGui")
		if playerGui then
			print("I found a PlayerGUI")		
		end
	end
end

I believe the issue is at game.Players.playerName because this is looking for a child of Players with the name playerName instead of substituting playerName for the actual player's name that's set in the variable.

Am I missing something here? Is there another way to do this? I have FilteringEnabled set to true.

3 comments

0

Fix the Lua Block please.

0

Haha we had the same idea

0

Maybe change line 5 to table.insert(InLobby, player.Name), and change line 11 to local playerName = InLobbyPlayer

1 answer

So I have

local PlayerService = game:GetService("Players")

and this line of code already obtains the Players PlayerGui.

So all I had to do was

local playerGui = InLobbyPlayer.PlayerGui

and it gets the player's GUIs.

This discussion is preserved as it was. New answers, comments, and votes are closed.