“Interface is not a valid member of PlayerGui”

Hello, I have a problem right now, what I’m trying to do is that when a user joins the experience, the serverscript makes a frame visible inside a ScreenGui, but this is not possible for me because it gives an error “Interface is not a valid member of PlayerGui “Players.(My username).PlayerGui””.

This is my script:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
      task.wait()
      local UI = Player.PlayerGui.Interface.Frame --here is the error
      UI.Visible = true
end)

Thank you for your help. (Sorry, my english is not perfect)

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	task.wait()
	local UI = Player:WaitForChild("PlayerGui"):WaitForChild("Interface") --here is the error
	UI.Visible = true
end)

Share a screenshot of your StarterGui folder.

4 Likes

You shouldn’t use server scripts for UI, use a local script inside the UI instead. It will help with your issue, but you should also use :WaitForChild() because thats why its erroring, because the UI isn’t loaded in yet.

3 Likes

Using a server script when referring to the PlayerGui instance of a player is fine. You should only not use server scripts when managing the StarterGui folder itself, since you’ll end up causing changes to the UI for everyone in the server.

3 Likes

Its not, you’re putting extra strain on the server, that can be avoided by doing it in a local script.
The server is already a laggy enough place, its why you don’t do things like tweens on the server, and instead you do it locally.

3 Likes

I’m aware of this but in some circumstances the UI has to be managed by the server.

3 Likes

Name me a time you need to manage UI on the server that can’t be done with remote events.

3 Likes

I have corrected the script, my PC was outside and I omitted the frame.

I could fix it, adding the :WaitForChild. Thanks!

I didn’t know how easy it was to fix it :sweat_smile:

3 Likes

Global timers, you can use FireAllClients() but handling it server-side works just as well.

Also don’t copy & reiterate my solutions in future, thanks.

2 Likes