How to get PlayerGui from ServerScript

Hi im trying to Enable/Disable/Edit A Gui from the ServerScript for All Players to see i tried this but it doesnt work local Players = game:GetService(“Players”)

Players.PlayerAdded:Connect(function(Player)

if Player.Parent:FindFirstChild("Humanoid") then
	local PlayerService = game:GetService("Players")
	local Player = PlayerService:GetPlayerFromCharacter(Player.Parent) -- GetPlayerFromCharacter
	
	
	

	Player.PlayerGui.UI.Enabled = false
	
	

end

end)

2 Likes

just Player.PlayerGui nothing to do with the if statement is needed. Like this:

local Players = game:GetService(“Players”)
Players.PlayerAdded:Connect(function(Player)
	Player.PlayerGui.UI.Enabled = false
end)

The PlayerAdded function checks if someone joins the game. It already leads to the player in the Players Category. No need to try finding the player.

1 Like

Humanoid isn’t a child of player, and this line in general is unnecessary. You don’t need to check if the player will have a Humanoid

You can try instead
Player:WaitForChild('PlayerGui').UI.Enabled = false

You have 2 player variables. You only need 1

local Players = game:GetService(“Players”)

Players.PlayerAdded:Connect(function(Player)
	Player:WaitForChild('PlayerGui').UI.Enabled = false
end)
1 Like

17:33:48.195 UI is not a valid member of PlayerGui “Players.Tunnells.PlayerGui” - S doesnt work :confused:

1 Like

Still gives me a error :confused:

1 Like

What’s the name of your UI? You have to replace it with its correct name of course

1 Like

The name is UI :sob: im not sure why its not working

1 Like

TEST.rbxl (23.5 KB) This is what i did

1 Like

Can you show us your explorer of StarterGui or PlayerGui? Not sure what’s going on there

1 Like

image

1 Like

Try

Player:WaitForChild('PlayerGui'):WaitForChild('UI').Enabled = false

script accessing ui before it loads

1 Like

Try this instead. I don’t know if the server recognizes there’s a GUI there

local Players = game:GetService(“Players”)

Players.PlayerAdded:Connect(function(Player)
	Player:WaitForChild('PlayerGui'):WaitForChild('UI').Enabled = false
end)

what @dollychun said lol

9 Likes

Thank you :smiley: it works but can i like edit the script while
like
change the text and stuff

1 Like

Using what has been posted … to do that, just replace this line …
Player:WaitForChild(‘PlayerGui’):WaitForChild(‘UI’).Enabled = false

With this …
local ui = Player:WaitForChild(‘PlayerGui’).UI
ui.ScreenGui.Frame.TextLabel.Text = “Whatever you want to say”
ui.Enabled = true

3 Likes