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

What is wrong with PlayerGui? [FOUND PROBLEM]

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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)

Ad
Log in to vote
1
Answered by
User#2 0
10 years ago

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")

Answer this question