Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Get PlayerGUI from Server Side Script?

Asked by 7 years ago

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.

0
Fix the Lua Block please. alphawolvess 1784 — 7y
0
Haha we had the same idea User#5748 20 — 7y
0
Maybe change line 5 to table.insert(InLobby, player.Name), and change line 11 to local playerName = InLobbyPlayer User#9949 0 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

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.

Ad

Answer this question