When I try to run script.Parent.ScreenGui2.waiting.Text="Waiting for more players...", along with some other code, it errors out saying "ScreenGui2 is not a valid member of PlayerGui", even though it is. This code is in a localscript, and the following is the entire function containing the code.
local function clickdetection(gui)
print(_G.notenoughplayers)
if _G.notenoughplayers==true then
print("not enough players")
buttontransparency(0.5)
script.Parent.ScreenGui2.waiting.Text="Waiting for more players..."
What makes this more confusing is that if I created a new localscript and inserted the above code, It would work. Why does it happen/How can I fix it?

4 comments
try to use :WaitForChild()
If this is a server-side script, there's your problem. Server-side scripts cannot access PlayerGui's descendants.
It looks like you're trying to use a regular script, that cannot mess with PlayerGui. You would have to change it over to a LocalScript, and use server remotes.
doing WaitForChild worked, thanks