Script 2:
local status = game.ReplicatedStorage.Status local TimerDisplay = script.Parent.TimerDisplay status.Changed:Connect(function() TimerDisplay.Text = status.Value end)
Script 1:
local roundLength = 40 local intermissionLength = 40 local InRound = game.ReplicatedStorage.InRound local status = game.ReplicatedStorage.Status local GameAreaSpawn = game.Workspace.GameAreaSpawn local LobbySpawn = game.Workspace.Lobby local function roundTimer() while wait() do for i = intermissionLength, 1, -1 do InRound.Value = false wait(1) status.Value = "Intermission: ".. i .."seconds left!" end for i = roundLength, 1, -1 do InRound.Value = false wait(1) status.Value = "Intermission: ".. i .." seconds left!" end end end spawn(roundTimer)
I did everything correctly but still, the text says "Label" even though it's suppose to be numbers that count down. There are 2 separate scripts that is needed to work. How do I fix this?
Here try this, accept if it works.
local roundLength = 40 local intermissionLength = 40 local InRound = game.ReplicatedStorage.InRound local status = game.ReplicatedStorage.Status local GameAreaSpawn = game.Workspace.GameAreaSpawn local LobbySpawn = game.Workspace.Lobby local function roundTimer() while true do for i = 1, intermissionLength do InRound.Value = false wait(1) status.Value = "Intermission: ".. i .."seconds left!" end for i = 1, roundLength do InRound.Value = false wait(1) status.Value = "Intermission: ".. i .." seconds left!" end end end spawn(roundTimer)
Ensure that the script you're modifying the TextLabel in is a LocalScript, and make sure you're using functions like :GetService()
and :WaitForChild()
.
--Make sure this is a LocalScript. local status = game:GetService("ReplicatedStorage"):WaitForChild("Status") local TimerDisplay = script.Parent.TimerDisplay status.Changed:Connect(function() TimerDisplay.Text = status.Value end)
It's possible that by the time the script reaches a line where you're assigning a variable to an instance that the instance has not yet loaded.
Do the same with the server script:
--Make sure this is a regular script, and preferably inside of ServerScriptService. local roundLength = 40 local intermissionLength = 40 local InRound = game:GetService("ReplicatedStorage"):WaitForChild("InRound") local status = game.ReplicatedStorage:WaitForChild("Status") local GameAreaSpawn = game.Workspace:WaitForChild("GameAreaSpawn") local LobbySpawn = game.Workspace:WaitForChild("Lobby") local function roundTimer() while wait() do for i = intermissionLength, 1, -1 do InRound.Value = false wait(1) status.Value = "Intermission: ".. i .."seconds left!" end for i = roundLength, 1, -1 do InRound.Value = false wait(1) status.Value = "There are ".. i .." seconds left in the game!" end end end spawn(roundTimer)
I also changed the second for
loop in the roundTimer()
function so that the text says that the game is currently in session.
If there are still any errors, or if anyone can spot one out that I made, please be sure to correct me.