Hey, so am trying to make a game where there is an arena. The arena opens every 2 minutes and then closes in 60 seconds.
I made a UI that displays the arena time and am trying to make it say that the arena opens in [TIME] however I want to do this on the server so that everyone can see the same time, how would I do this?
Have a script in game.ServerScriptService and name it something like “ArenaTimer”
Then just put this in the script:
local currentTime = 60
while true do
currentTime = currentTime - 1
wait(1)
if currentTime = 0 then
currentTime = 60
end
end
Then just update the GUI yourself.
You can do this but with an IntValue in repstorage instead so you can check if the IntValue is changed in your localscript that’s in your textbox in order to update the text.
Thanks, Ill try that (30characters)
Let me work something out for tthis, i’ll help u in a second
This should do. I tested it myself, for GUI you could use IntValue.
local CurrentTimer = 60
local War = false
while true do
wait(1)
if War == false then
WaitTimer = WaitTimer - 1
end
if WaitTimer == 0 then
War = true
CurrentTimer = CurrentTimer - 1
-- When war start (Enter own code down here)
end
if CurrentTimer == 0 then
War = false
-- When war is over (Enter own code down here)
end
end
Let me know if you need futher help
Did you put this in a local script or a server script?
If you want your code to be faster I would suggest using a remote event that fires on all clients to give the current time left. If you don’t know how to use remotes you can use an IntValue as suggested by @aDistractr. Make sure to put the IntValue inside ReplicatedStorage so clients can access it.
I tried it in a serverscript .
In that case you would need to fire a remote event in order to change the text.
Never added something to change the text, could be done differently too If am not wrong.
But using a remove event is way better
Using a remote in this case would be very simple
Server:
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Timer")
for i=1, 60 do
wait(1)
Remote:FireAllClients(i)
end
Client:
local TextLabel = script.Parent
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Timer")
Remote.OnClientEvent:Connect(function(timeLeft)
TextLabel.Text = "Time Left: "..timeLeft.."s"
end)
You can use a number value object and update it from the server , this will use less bandwidth than remote events .
However , if you want to do more complex things you can use Quenty’s Time Sync Library from the Nevermore Engine
Hey,thanks that worked perfectly!
Hey, I tried that but whenever I tried to update the UI it would only update it once, Stellar_X made a simple way by firing events that would update the Ui so it alright now, thanks
You could use an intvalue using eventually
game.ReplicatedStorage.IntValue.Value.Changed:Connect(function()
--code
end)