So I am trying to make a game that has an intermission and a game timer e.t.c. Only problem is if new players join, they will not be updated to the current time. So how would I loop that every second while running the timer script?
while wait(1) do
RemoveEvent:FireServer()/FireClient()
end
You should only need to fire once when the player joins. You would fire the remaining time of the minigame at the tick time, so something like this:
--Server
local event = game.ReplicatedStorage.RemoteEvent
local timeLeft = 1000
game.Players.PlayerAdded:Connect(function(player)
event:FireClient(player,timeLeft,tick())
end)
--Client
local TimeLeft
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(timeLeft,serverTick)
timeLeft = timeLeft - (tick() - serverTick)
if timeLeft <= 0 then
print("Round has ended when player started")
end
end)
while wait(1) do
if timeLeft then
if timeLeft > 0 then
timeLeft = timeLeft - 1
end
end
end
No like adding on to my other script
Wait so like this will fire a remote event every second?
No it will fire when the player joins or a new round starts, so it is less laggy and doesn;t exhaust your remote calling limit
Where are you firing this? Server or Client
Im firing the remote event on the server side
Then use FireAllCIients
(30 chars)
You could place the “time” as a IntValue in ReplicatedStorage (The Value will obviously be the time).
And from there, you could run this in your LocalScript somewhere:
while true do
wait() --It will instantly update the value
--[[Your Timer Label = game.ReplicatedStorage.Timer.Value
Example:
script.Parent.Text = game.ReplicatedStorage.Timer.Value
]]--
end
(Make sure your handling “the timer” in a Script so it can’t be messed with client-sided)
I am already using :FireAllClients. I just need it so that it fires every second or so
So just this:
while (true) do
wait(1)
REMOTEVENTPATH:FireAllClients(yourargs)
end
Add a wait(1)??? 30 charssssssss
No but like I already have a script that works the intermission and game timer, so how do I combine the two so that it still fires every second?
Just make an IntValue in ReplicatedStorage, change it every second on the server, and then the client will be able to access that IntValue with the value changed every second.
repeat
game.ReplicatedStorage.Event:FireAllClients(
wait(1)
until false
Are you firing it from the client or the server?
To perform multiple tasks at the same time within the same script, try using coroutines. This will allow for multiple threads.
coroutine.resume(coroutine.create(function()
while wait(1) do
remoteevent:FireAllClients()
end
end))
I’m firing from server (30 chars)
Where would I put the rest of my code?