I’m trying to create a countdown timer. This is being made in a server script in ServerScriptService.
local PlayerGui = game.Players:WaitForChild("LocalPlayer").PlayerGui
function Rounds()
PlayerGui.MatchHUD.Countdown.Text = "10"
for i = 1, 10, 1 do
PlayerGui.MatchHUD.Countdown.Text = tostring(i)
wait(1)
end
SelectPart()
return
end
Anyone know how to fix this while keeping it in a Server Script? Many answers / tutorials I’ve watched just said to switch to local, but I need this to be in a Server Script.
You most likely could make a IntValue in Workspace, ReplicatedStorage and then you change the value of the IntValue to the countdown using the SS-Script and just detect from the Client if the value has been changed, if so then you change the text
But I need all players to see the function being run, not only the one who it’s affecting. So I need it to be in a Server Script. Here’s my full script:
local PlatesFolder = game.Workspace.Game.Map.Plates
local Floor = game.Workspace.Game.Map.Map.Floor
local Countdown = game.StarterGui.MatchHUD.Countdown
local Plates = PlatesFolder:GetChildren()
local PlayerGui = game.Players:WaitForChild("LocalPlayer").PlayerGui
function SelectPart()
local randomPlate = Plates[math.random(1, #Plates)]
-- [MAKING THE ATTACKS]
local function LavaAttack()
-- In the future, I'd turn this into a tween
-- Set player health to 0
print("LavaAttack")
end
local function SpinAttack()
-- In the future, I'd turn this into a tween
print("SpinAttack")
end
local function Shrink()
-- In the future, I'd turn this into a tween
print("Shrink")
end
local function Cage()
-- In the future, I'd turn this into a tween
print("Cage")
end
-- [Play a random attack on this plate]
local Functions = {Cage, Shrink, SpinAttack, LavaAttack}
local ChosenFunction = Functions[math.random(1, #Functions)]
ChosenFunction()
end
function Rounds()
PlayerGui.MatchHUD.Countdown.Text = "10"
for i = 1, 10, 1 do
PlayerGui.MatchHUD.Countdown.Text = tostring(i)
wait(1)
end
SelectPart()
return
end
Rounds()
--other variables
--delete playergui
local remote = --add remotevent
function rounds()
remote:FireAllClients(10)
task.wait(10) -- change this to something more in sync
SelectPart()
--no need for return
end
--in your client script
local player = game.Players.LocalPlayer
local playerUI = player.PlayerGui
local label = playerUI.MatchHUD.Countdown.Text
local remote -- your remote
remote.OnClientEvent:Connect(function(time: number)
label.Text = time
for i=time, 0, -1 do
label.Text = i
task.wait(1)
end
end)