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

How do I find a players Gui through a script?

Asked by 10 years ago
function fun(player)
local label = player.PlayerGui.TimeLeft.Frame.TimeLeftLabel
local ready = player.PlayerGui.TimeLeft.Frame.Ready.ReadyToVisit
end
game.Players.PlayerAdded:connect(fun)

Error output comes out with "PlayerGui is not a valid member of Player "WHAT AM I DOING WRONG???

Here is the Workspace thing

Players
    Player1
        PlayerGui
            TimeLeft
                Frame
                    Ready
                        ReadyToVisit
                    TimeLeftLabel

3 answers

Log in to vote
0
Answered by
DrJonJ 110
10 years ago

The issue is that it hasn't loaded yet. Use :WaitForChild() to pause the script until the item is found.

Here:

function fun(player)
    player:WaitForChild('PlayerGui')
    wait(0.5) -- let the other stuff load up
    local label = player.PlayerGui.TimeLeft.Frame.TimeLeftLabel
    local ready = player.PlayerGui.TimeLeft.Frame.Ready.ReadyToVisit
end

game.Players.PlayerAdded:connect(fun)
Ad
Log in to vote
0
Answered by 10 years ago

in a local script you can do something like this in a server-sided script i suggest using the PlayerAdded event

Player = game.Players.LocalPlayer
repeat wait() until Player:FindFirstChild("PlayerGui")
local PGui = Player:FindFirstChild("PlayerGui")
Log in to vote
-1
Answered by 10 years ago
local plr = game.Players.LocalPlayer
repeat wait() until plr:FindFirstChild("PlayerGui")

function findInPlayerGui(name, parent)
    if plr.PlayerGui:FindFirstChild(tostring(parent)) ~= nil then
        prnt = plr.PlayerGui:FindFirstChild(tostring(parent))
        if prnt:FindFirstChild(tostring(name)) ~= nil then
            return prnt:FindFirstChild(tostring(name))
        else
            return false
        end
    else
        return false
    end
end

function fun(player)
local TMFrame = findInPlayerGui("Frame", "TimeLeft")
local label = findInPlayerGui("TimeLeftLabel", TMFrame)
local TMReady = findInPlayerGui("Ready", TMFrame)
local ready = findInPlayerGui("ReadyToVisit", TMReady)
end

fun(plr)

This is in local script, also this might be long but its good.

Answer this question