Code does not change text when round starts. Stays label

this script starts a round of hide and go seek, i just want to change the text before the round starts, when the round starts and who the seeker is. but it stays label. here is my code:

local timer = 20

local recol = 0

---------------------------------------------
local screengui = game.StarterGui.ScreenGui

local texte = screengui.TextLabel





game.Players.PlayerAdded:Connect(function(plr)
	recol = recol + 1
	plr.Team = game.Teams.Spectator
	print("Added 1")
end)

game.Players.PlayerRemoving:Connect(function(plr)
	recol = recol - 1
	print("Removed 1")
end)

task.spawn(function()
	while task.wait(1) do
		if recol >= 2 then
			
			wait(5)
			
			texte.Text = "Round Starting soon!"	
			
			task.wait(20)
			
			texte.Text = "Round Started!"
		
			
			local playerCharacters = {}
			for _, character in pairs(workspace:GetChildren()) do
				if game.Players:FindFirstChild(character.Name) then
					table.insert(playerCharacters, character)
				end
			end
			local Seek = playerCharacters[math.random(1, #playerCharacters)]
			print(Seek)
			
			texte.Text = `{Seek} is the seeker!`
			
			
			
			local function MakeSeeker()
				if recol >= 2 then
					game.Players:GetPlayerFromCharacter(Seek).Team = game.Teams.Seeker
					Seek.HumanoidRootPart.Position = Vector3.new(130.046, 5.5, 0.84)
				end
			end
			if game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Spectator then
				MakeSeeker()
			    
				--Seek.Team = game.Teams.Seeker
			elseif game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Seeker then
				print("this guy is murderer!")
				return nil
			end
			
			for _,v in pairs(playerCharacters) do
				if v.Name ~= Seek.Name then
					if game.Players:GetPlayerFromCharacter(v).Team == game.Teams.Spectator then
						print('aaaa')
						game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Hiders
				
					end
				end
			end		
			
			wait(5)
			for _,v in pairs(playerCharacters) do
				game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Spectator 
				
				texte.Text = "Round Over!"
			end
		end
	end
end)

5 Likes

the problem is here:

local screengui = game.StarterGui.ScreenGui

instead you should do

local screengui = "put player here".PlayerGui.ScreenGui
3 Likes

can i put on

game.players? or not?

1 Like

no it needs to be the target player

1 Like

i want the whole server to be able to see the change of the text.

then i would use a for loop for all the players and change the text that way

1 Like
local timer = 20

local recol = 0

---------------------------------------------






game.Players.PlayerAdded:Connect(function(plr)
	recol = recol + 1
	plr.Team = game.Teams.Spectator
local texte = plr:WaitForChild("PlayerGui").ScreenGui.TextLabel
	print("Added 1")
	task.spawn(function()
		while task.wait(1) do
			if recol >= 2 then
				
				wait(5)
				
				texte.Text = "Round Starting soon!"	
				
				task.wait(20)
				
				texte.Text = "Round Started!"
			
				
				local playerCharacters = {}
				for _, character in pairs(workspace:GetChildren()) do
					if game.Players:FindFirstChild(character.Name) then
						table.insert(playerCharacters, character)
					end
				end
				local Seek = playerCharacters[math.random(1, #playerCharacters)]
				print(Seek)
				
				texte.Text = `{Seek} is the seeker!`
				
				
				
				local function MakeSeeker()
					if recol >= 2 then
						game.Players:GetPlayerFromCharacter(Seek).Team = game.Teams.Seeker
						Seek.HumanoidRootPart.Position = Vector3.new(130.046, 5.5, 0.84)
					end
				end
				if game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Spectator then
					MakeSeeker()
				    
					--Seek.Team = game.Teams.Seeker
				elseif game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Seeker then
					print("this guy is murderer!")
					return nil
				end
				
				for _,v in pairs(playerCharacters) do
					if v.Name ~= Seek.Name then
						if game.Players:GetPlayerFromCharacter(v).Team == game.Teams.Spectator then
							print('aaaa')
							game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Hiders
					
						end
					end
				end		
				
				wait(5)
				for _,v in pairs(playerCharacters) do
					game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Spectator 
					
					texte.Text = "Round Over!"
				end
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	recol = recol - 1
	print("Removed 1")
end)
2 Likes

cant i just fire a remote event that changes the text in the server and not the client? or is that impossible

do what dutycall did, thats what i meant when using the target player

1 Like

i get this error, i tried to run it multiple times and this is the same outcome.

can you send a screenshot of playergui when you test it

local timer = 20

local recol = 0

---------------------------------------------






game.Players.PlayerAdded:Connect(function(plr)
	recol = recol + 1
	plr.Team = game.Teams.Spectator
local texte = plr:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("TextLabel")
	print("Added 1")
	task.spawn(function()
		while task.wait(1) do
			if recol >= 2 then
				
				wait(5)
				
				texte.Text = "Round Starting soon!"	
				
				task.wait(20)
				
				texte.Text = "Round Started!"
			
				
				local playerCharacters = {}
				for _, character in pairs(workspace:GetChildren()) do
					if game.Players:FindFirstChild(character.Name) then
						table.insert(playerCharacters, character)
					end
				end
				local Seek = playerCharacters[math.random(1, #playerCharacters)]
				print(Seek)
				
				texte.Text = `{Seek} is the seeker!`
				
				
				
				local function MakeSeeker()
					if recol >= 2 then
						game.Players:GetPlayerFromCharacter(Seek).Team = game.Teams.Seeker
						Seek.HumanoidRootPart.Position = Vector3.new(130.046, 5.5, 0.84)
					end
				end
				if game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Spectator then
					MakeSeeker()
				    
					--Seek.Team = game.Teams.Seeker
				elseif game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Seeker then
					print("this guy is murderer!")
					return nil
				end
				
				for _,v in pairs(playerCharacters) do
					if v.Name ~= Seek.Name then
						if game.Players:GetPlayerFromCharacter(v).Team == game.Teams.Spectator then
							print('aaaa')
							game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Hiders
					
						end
					end
				end		
				
				wait(5)
				for _,v in pairs(playerCharacters) do
					game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Spectator 
					
					texte.Text = "Round Over!"
				end
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	recol = recol - 1
	print("Removed 1")
end)
1 Like

the server cannot see what’s on the client
you’d need to fire a remote from the server to change the text

1 Like

such as? can you give me a example. i have hard time with remote events while its really easy people say.

Screenshot_2023-08-01_12-22-57
typically you’d have a structure like this
( remote events in replicated storage, etc)

a simple example would be like

Screenshot_2023-08-01_12-24-28

Screenshot_2023-08-01_12-24-43

this example is the server firing all clients, you can fire a single client from the server, or the client firing an event to the server

1 Like

How about you create a String Value instead by using server to change the String value
On client when String value changed set your text to that String value

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.