Gui only Shows for 1 Person

GUI is showing to only 1 person

here is the video on that:

Below is the Code and it’s in Server Script Service.

--Length Variables
local roundLength = game.ReplicatedStorage.roundLength
local gameStartLength = game.ReplicatedStorage.gameStartLength


while wait() do
	
	for _,player in pairs(game.Players:GetPlayers()) do


		wait(10)

		-- Player Count
		local playerCount = #game.Players:GetPlayers()

		--Game Status 
		local gameStatus = game.ReplicatedStorage.gameStatus
		gameStatus.Value = "Waiting for Game to Start..."

		--Round Status 
		local roundStatus = player.PlayerGui:WaitForChild("InRound")

		--Guis
		local bgFinderHider = player.PlayerGui.Bg
		local finderHiderChoosingFrame = player.PlayerGui.HiderFinderGui.FinderBGGui

		--Texts
		local hiderFinderText = finderHiderChoosingFrame.Frame.TextLabel

		--Starting Game
		while wait() do

			--Checking if there are enough players to Start the Game
			if playerCount >= 1 then
				for i = gameStartLength.Value,0,-1 do

					roundStatus.Value = false
					wait(1)
					gameStatus.Value = "Game Starts in "..i.." Seconds"
					bgFinderHider.Enabled = false

				end

				-- choosing a hider from the players in the game
				local hider = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]

				print(hider.Name)

				bgFinderHider.Enabled = true


				finderHiderChoosingFrame:TweenPosition(
					UDim2.new(0.258,0,0.2,0),
					"In",
					"Quad",
					1,
					false
				)

				--TypeWriter Function
				local function typeWrite(object, text) 
					for i = 1,#text,1  do
						wait(0.3)
						object.Text = string.sub(text,1,i)
					end
				end

				wait(2)

				-- Checking if player is a hider or not and showing them the text
				if player ~= hider then

					typeWrite(hiderFinderText, 'Finder')

				else

					typeWrite(hiderFinderText, 'Hider')

				end

				wait(5)

				finderHiderChoosingFrame:TweenPosition(
					UDim2.new(0.258,0,1,0),
					"Out",
					"Quad",
					1,
					false
				)

				wait(1)

				hiderFinderText.Text = ""

			else
				gameStatus.Value = "Waiting for Enough Players..."
			end
		end

	end

end

Please Help me with this Problem1 I am trying to figure it out for more than 4 days :frowning:

2 Likes

Please Help me if anyone knows the issue :frowning: I will be thankful to you :slight_smile:

I believe it’s because you are looping through the players without creating a coroutine or something of the sort. Try this

--Length Variables
local roundLength = game.ReplicatedStorage.roundLength
local gameStartLength = game.ReplicatedStorage.gameStartLength


while wait() do

	for _,player in pairs(game.Players:GetPlayers()) do


		coroutine.wrap(function() --Creates a new thread
			wait(10)

			-- Player Count
			local playerCount = #game.Players:GetPlayers()

			--Game Status 
			local gameStatus = game.ReplicatedStorage.gameStatus
			gameStatus.Value = "Waiting for Game to Start..."

			--Round Status 
			local roundStatus = player.PlayerGui:WaitForChild("InRound")

			--Guis
			local bgFinderHider = player.PlayerGui.Bg
			local finderHiderChoosingFrame = player.PlayerGui.HiderFinderGui.FinderBGGui

			--Texts
			local hiderFinderText = finderHiderChoosingFrame.Frame.TextLabel

			--Starting Game
			while wait() do

				--Checking if there are enough players to Start the Game
				if playerCount >= 1 then
					for i = gameStartLength.Value,0,-1 do

						roundStatus.Value = false
						wait(1)
						gameStatus.Value = "Game Starts in "..i.." Seconds"
						bgFinderHider.Enabled = false

					end

					-- choosing a hider from the players in the game
					local hider = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]

					print(hider.Name)

					bgFinderHider.Enabled = true


					finderHiderChoosingFrame:TweenPosition(
						UDim2.new(0.258,0,0.2,0),
						"In",
						"Quad",
						1,
						false
					)

					--TypeWriter Function
					local function typeWrite(object, text) 
						for i = 1,#text,1  do
							wait(0.3)
							object.Text = string.sub(text,1,i)
						end
					end

					wait(2)

					-- Checking if player is a hider or not and showing them the text
					if player ~= hider then

						typeWrite(hiderFinderText, 'Finder')

					else

						typeWrite(hiderFinderText, 'Hider')

					end

					wait(5)

					finderHiderChoosingFrame:TweenPosition(
						UDim2.new(0.258,0,1,0),
						"Out",
						"Quad",
						1,
						false
					)

					wait(1)

					hiderFinderText.Text = ""

				else
					gameStatus.Value = "Waiting for Enough Players..."
				end
			end
		end)()

	end

end
3 Likes

that turns into another problem : / and so that is not fixing !

Probably because of that “while wait() do”. What is that supposed to do?

Also, I would like to hear what that new issue is, seeing as your current issue most likely is because of the “wait 10” that you have in your script.

3 Likes

that while is for to run that for loop all the time like run the round system for ever.

1 Like

You might wanna make that event-based, or try to make it work at least once before you go full out.

1 Like

@MrREDDeveloper

It definitely is that wait(10). This is all running on one for loop, so it takes care of the first player before it moves on to the next. In other words, it will run the countdown for one player at a time. In this case, you may consider deciding what everyone’s role is beforehand, and then just handing off everything else (like the reflection of the countdown and displaying the role) to the client.

1 Like

if i remove that wait, then the for loop will run very fast as i have tested it

1 Like

that may be a little bit complex but will try!

1 Like

Well if you don’t remove it, it’s going to move too slow. You should want it to move as fast as possible. What you need to do is reorganize your code. You’re setting the round information for every single player. All of that should be done before you loop through your players, like I said. The only thing you should do with your players is reflect the information to their client, and then later start the round for them.

1 Like

but how is that even possible like its a bit complecated to show gui before starting the round as of the script!

1 Like

Whilst I’m sure you’re well on your way through this project and comfortable with your way of working, you should consider moving all of your interface based code over to the clientside where it belongs. You can then have the server fire events to trigger a response from your user interface.

The server is for backend processes.
The client is for frontend processes.

Take a look at some industry styled information surrounding this concept.

Perhaps some bed time reading? :slight_smile:

4 Likes