What do you want to achieve? Keep it simple and clear!
i want to make a round/lobby system for my game
What is the issue? Include screenshots / videos if possible!
it worked at first but when my friend joined the timer went twice as fast and when a second friend joined it went thrice as fast
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
i tried fixing it myself but i dont know whats wrong. i looked for solutions in the hub but i didnt find anything
this is my script:
local players = game.Players
local rs = game.ReplicatedStorage
local values = rs.Values
local round = values.Round
local minutes = values.TimerM
local seconds = values.TimerS
players.PlayerAdded:Connect(function(plr)
local function roundEnd()
round.Value = false
minutes.Value = 0
seconds.Value = 40
local chr = plr.Character or plr.CharacterAdded:Wait()
local timertext = plr.PlayerGui:WaitForChild("RoundGUI"):WaitForChild("Timer")
local text = plr.PlayerGui:WaitForChild("RoundGUI"):WaitForChild("TextLabel")
chr.HumanoidRootPart.CFrame = workspace.LobbySpawn.Part.CFrame
text.Text = "INTERMISSION"
while round.Value == false do
wait(1)
if seconds.Value > 0 then
seconds.Value -= 1
if seconds.Value < 10 then
timertext.Text = minutes.Value .. ":0" .. seconds.Value
else
timertext.Text = minutes.Value .. ":" .. seconds.Value
end
elseif minutes.Value > 0 and seconds.Value == 0 then
minutes.Value -= 1
seconds.Value = 59
timertext.Text = minutes.Value .. ":" .. seconds.Value
else
print("round started")
local function roundStart()
round.Value = true
wait(1)
local chr = plr.Character or plr.CharacterAdded:Wait()
local timertext = plr.PlayerGui:WaitForChild("RoundGUI"):WaitForChild("Timer")
local text = plr.PlayerGui:WaitForChild("RoundGUI"):WaitForChild("TextLabel")
chr.HumanoidRootPart.CFrame = workspace.RoundSpawn.Part.CFrame
text.Text = "ROUND IN PROGRESS"
minutes.Value = 4
seconds.Value = 0
while round.Value == true do
wait(1)
if seconds.Value > 0 then
seconds.Value -= 1
if seconds.Value < 10 then
timertext.Text = minutes.Value .. ":0" .. seconds.Value
else
timertext.Text = minutes.Value .. ":" .. seconds.Value
end
elseif minutes.Value > 0 and seconds.Value == 0 then
minutes.Value -= 1
seconds.Value = 59
timertext.Text = minutes.Value .. ":" .. seconds.Value
else
print("round ended")
roundEnd()
end
end
end
roundStart()
end
end
end
roundEnd()
end)
i don’t know what’s wrong and how to fix this problem. any help would be appreciated!
i’m pretty sure you don’t need to make it run when a player joins, since the script only needs to run one time (when the server starts up from the first player joining)
also, i suggest moving the roundStart function out of the roundEnd function, since it’s causing unnecessary nesting in your code
Also dont make it when the players is added, make it happens when their is enough players / make it happen when the game starts if it makes you happy ig
okay, since i didn’t specify i put the playerAdded there so i can get the player to change the timer gui. Everyone’s telling me to not use it but is there a different way i could change the timer for all players?
wait for a player to join then call the functions, you can do like
local Players = game:GetService("Players");
function roundEnd()
...
end
function roundStart()
...
end
--// at the end of script
repeat task.wait() until #Players:GetPlayers() > 0;
roundEnd();
Don’t use players.PlayerAdded:Connect(function(plr) to start rounds. Everytime a new player joins the game it creates a new thread, so when a 2nd player joins the game the script will run the timer while loop for them too, so you’ll have the timer running 2 times. That’s why the timer goes twice as face when a second person joins.
I would use a remote event for gui changes and for each gui change in the server script do a :FireAllClients(GuiText) and have it listen for the remote event in the local script (gui script) and change the gui based on what you passed through the remote event
GUIs should never be controlled from the server. That is a client’s job. As @LuhLuaProgrammer said, have the server replicate timer state to all clients, then have each client update the UI locally. You can use a StringValue or a RemoteEvent