Countdown isn't the same for other players

So… made an Countdown script for my game “YoB”, the problem is just that every player gets their countdown reset and i don’t know how to change it. Can somebody help me with this? Just asking and thank you for your help

The Videos of the bug (Recorded at the same time):


The Script:

local countdownUI = script.Parent
local Countdown
local RoundStarted = false
local CharacterSelect = false
local Lobbymusic = game.SoundService:FindFirstChild("I'm Sad but I Don't Know Why (Lobby Theme)")
local countdownsound = script.Countdown
local countdownsoundlastseconds = script["Countdown (last seconds)"]
local CSMusic = game.SoundService:FindFirstChild("Character Select (Placeholder)")
local PlaceholderMusic = game.SoundService:FindFirstChild("Test Stage")

local function StopAllMusic()
	if Lobbymusic and Lobbymusic.IsPlaying then
		Lobbymusic:Stop()
	end
	if CSMusic and CSMusic.IsPlaying then
		CSMusic:Stop()
	end
	if PlaceholderMusic and PlaceholderMusic.IsPlaying then
		PlaceholderMusic:Stop()
	end
end

while true do
	if RoundStarted == false and CharacterSelect == false then
		StopAllMusic()
		Lobbymusic.Looped = true
		Lobbymusic:Play()
		Countdown = 50
		while Countdown > 0 do
			countdownUI.Text = "Intermission: "..Countdown
			wait(1)
			if Countdown > 4 then
				countdownsound:Play()
			else
				countdownsound:Stop()
				countdownsoundlastseconds:Play()
			end
			Countdown = Countdown -1
		end
		countdownUI.Text = "Intermission: "..Countdown
		CharacterSelect = true
	end
	
	if RoundStarted == false and CharacterSelect == true then
		Lobbymusic.Looped = false
		StopAllMusic()
		CSMusic:Play()
		Countdown = 20
		while Countdown > 0 do
			countdownUI.Text = "Character Select: "..Countdown
			wait(1)
			if Countdown > 4 then
				countdownsound:Play()
			else
				countdownsound:Stop()
				countdownsoundlastseconds:Play()
			end
			Countdown = Countdown -1
		end
		countdownUI.Text = "Time: "..Countdown
		CharacterSelect = false
		RoundStarted = true
	end
	
	if RoundStarted == true and CharacterSelect == false then
		StopAllMusic()
		PlaceholderMusic:Play()
		Countdown = 120
		while Countdown > 0 do
			countdownUI.Text = "Time: "..Countdown
			wait(1)
			if Countdown > 4 then
				countdownsound:Play()
			else
				countdownsound:Stop()
				countdownsoundlastseconds:Play()
			end
			Countdown = Countdown -1
		end
	end
	countdownUI.Text = "Character Select: "..Countdown
	CharacterSelect = false
	RoundStarted = false
end

Looks like this is being done on the client. Maybe move the countdown logic to the server.
Add an IntValue named Countdown in ReplicatedStorage to keep the count consistent.

ServerScriptService.ServerScript

local rs = game:GetService("ReplicatedStorage")
local countdown = rs:WaitForChild("Countdown")
local mode = rs:WaitForChild("CountdownMode")

while true do
	mode.Value = "Intermission"
	for i = 50, 0, -1 do
		countdown.Value = i
		task.wait(1)
	end

	mode.Value = "Character Select"
	for i = 20, 0, -1 do
		countdown.Value = i
		task.wait(1)
	end

	mode.Value = "Match"
	for i = 120, 0, -1 do
		countdown.Value = i
		task.wait(1)
	end
end

PlayerGui.ScreenGui.CountdownLabel.LocalScript

local gui = script.Parent
local label = gui:WaitForChild("CountdownLabel")
local rs = game:GetService("ReplicatedStorage")
local countdown = rs:WaitForChild("Countdown")
local mode = rs:WaitForChild("CountdownMode")

local function update()
	label.Text = mode.Value..": "..countdown.Value
end

countdown:GetPropertyChangedSignal("Value"):Connect(update)
mode:GetPropertyChangedSignal("Value"):Connect(update)

update()

I put the script in the CountdownLabel to avoid confusion.

2 Likes

So… the scripts works, i just have a question. What’s actually “CountdownMode”? Just asking

found it out, it was a StringValue

and btw, thank you for the help and have a nice day

1 Like

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