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
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
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.
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.
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.