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

What is wrong with PlayerGui? [FOUND PROBLEM]

I had attempted to make a Message script that only a Specific player can see, but the Output said 'PlayerGui is not a vaild member of Player', what happened? ;-;

Here is the script;

fucntion oc(msg,time,type,par)
m=Instance.new(type)
m.Parent=par
m.Text=msg
wait(time)
if m~=nil then
m:remove()
end end

oc("Welcome to the game.",4,"Hint",game:GetService("Players").LocalPlayer.PlayerGui)

-- ANSWER -- I found out what the problem was, FilteringEnabled was keeping me from using PlayerGui. o_e

2 answers

Well I am assuming that the function is firing before the PlayerGui is instantiated. So just add

repeat wait() until game:GetService("Players").LocalPlayer.PlayerGui;

(You mispelled function by the way)

This is happening because the script is probably running before the PlayerGui is created, so it doesn't exist!

All Objects inherit a WaitForChild method, which waits for a child with the given name. It also returns that child when it is found.

On the last line, replace game:GetService("Players").LocalPlayer.PlayerGui with:

GetService("Players").LocalPlayer:WaitForChild("PlayerGui")

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