ScreenGui is not a valid member of PlayerGui

Hello! I tried to make a PlayerCounter, but it doesn’t work.
Error: ScreenGui is not a valid member of PlayerGui

Script:

--ServerScript
local plrNum

game.Players.PlayerAdded:Connect(function(plr)
 	plrNum = #game.Players:GetChildren()
	plr:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text = "Players:"..plrNum
end)

game.Players.PlayerRemoving:Connect(function(plr)
	plrNum = #game.Players:GetChildren() - 1
	plr:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text = "Players:"..plrNum
end)
5 Likes

The error says it all. ScreenGui isn’t a child of PlayerGui. Did you rename your Screengui? Did you try using WaitForChild for the screengui?

12 Likes

image

1 Like

It works now. Thank you! I forgot to use WaitForChild for the ScreenGui. ;-;

2 Likes