Script wont make the UI visible

Hello, i made a script that would look how many players there are in a server, whenever it’s higher or equal to two players, the round will start. whenever there are not enough players or enough players, the script should make the UI visible and say if it’s not enough or there is enough. but for some reason, the script enabled the UI but wont make the text appear ingame, but in studio when i enable it, it appears.

here’s my code:


local playercount = 0

local Grow = game.Workspace.Grow
local textchange = game.ReplicatedStorage:WaitForChild("TextChanger")

game.Players.PlayerAdded:Connect(function(plr)
	playercount = playercount + 1
	print('player added')
	local text = plr:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("TextLabel")
	
	
	
	
	wait(5)
	
	
	if playercount >= 2 then
		print("Enough players.")
		if game.StarterGui.ScreenGui.Enabled == false then
			game.StarterGui.ScreenGui.Enabled = true 
			
			textchange:FireAllClients("ScreenGui", "TextLabel", "Round starting in 5 seconds.")
			
			wait(5)
			
			game.StarterGui.ScreenGui.Enabled = false
		end


		while true do
			wait(0.01)

			Grow.Size = Grow.Size + Vector3.new(0.03,0,0)

			Grow.Position = Grow.Position + Vector3.new(0,0.015,0)
		end
	else

		print('not starting')

		if game.StarterGui.ScreenGui.Enabled == false then
			game.StarterGui.ScreenGui.Enabled = true
			
			print("UI enabled.")
			
			textchange:FireAllClients("ScreenGui", "TextLabel", "Not enough players.")
			
			--wait(5)
			
			
			--game.StarterGui.ScreenGui.Enabled = false


		end
		

	end
	


	
end)
game.Players.PlayerRemoving:Connect(function()
	playercount = playercount - 1
	print('player removed')
end)

Here are photos with explanation.


Enables the UI and the UI should show up.


as you can see, on the right it says its enabled but you cant see anything, the textlabel is visible.

Now we will enable it when we are not ingame, lets see if it is visible.

hmm thats weird, when im not in the game, it shows. but when im in it, it doesnt.

anybody got a fix?

2 Likes

When you’re in Studio, changing StarterGui changes your screen, but in game the player has a seperate screen called PlayerGui in the player object (which is cloned from StarterGui), and that is the one changing the player’s screen, not StarterGui.
For this situation, you can either fire a remote event to clients and change it there, or change them for each player like this on the server:

game.Players.PlayerAdded:Connect(function(plr)
	playercount = playercount + 1
	print('player added')
	local text = plr:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("TextLabel")

	wait(5)

	if playercount >= 2 then
		print("Enough players.")
		for i, player1 in pairs(game.Players:GetPlayers()) do -- loop through each player in game
			if player1.PlayerGui.ScreenGui.Enabled == false then -- access playerGui through player
				player1.PlayerGui.ScreenGui.Enabled = true 

				textchange:FireClient(player1, "ScreenGui", "TextLabel", "Round starting in 5 seconds.") -- only fire client to player with ScreenGui disabled

				wait(5)

				player1.PlayerGui.ScreenGui.Enabled = false
			end


			while true do
				wait(0.01)

				Grow.Size = Grow.Size + Vector3.new(0.03,0,0)

				Grow.Position = Grow.Position + Vector3.new(0,0.015,0)
			end
		end
	else

		print('not starting')
		for i, player1 in pairs(game.Players:GetPlayers()) do -- loop through each player in game
			if player1.PlayerGui.ScreenGui.Enabled == false then
				player1.PlayerGui.ScreenGui.Enabled = true

				print("UI enabled.")

				textchange:FireClient(player1, "ScreenGui", "TextLabel", "Not enough players.")

				--wait(5)
				--player1.PlayerGui.ScreenGui.Enabled = false
			end

		end
	end
end)
1 Like