What does code do?
The code works by making several functions that work as steps to make the round, and then restarting it by calling the repeat function to look for players.
Not satisfied because?
I’m not satisfied with it because it feels strange that I have to do it once after every function and then it’s infinite forever.
Considered improvements?
I’ve considered making it more controlled by not making the very start of my countdown in 1 task.spawn()
How do I want to improve code?
I’m not sure how I want to improve this code but I feel like this system could be more optimized.
Main script:
local start = 30
local ending = 0
local increase = -1
function countdown()
game.ReplicatedStorage.CountdownEvent:FireAllClients(start,ending,increase)
game.ReplicatedStorage.StopEvent.OnServerEvent:Connect(function(plr,text)
if text == "0" then
local char = plr.Character
char:MoveTo(workspace.Map.Position + Vector3.new(math.random(-12,12),5,math.random(-12,12)))
game.ReplicatedStorage.PlayingEvent:FireAllClients(start,ending,increase)
end
end)
end
function runningup()
while task.wait() do
local players = game:GetService("Players")
repeat
task.wait(1)
until #players:GetPlayers() >= 1
if #players:GetPlayers() >= 1 then
task.spawn(countdown)
break
end
end
end
game.ReplicatedStorage.RestartEvent.OnServerEvent:Connect(function(plr, text)
if true and text == "0" then
local char = plr.Character
char:MoveTo(workspace.Lobby.Position + Vector3.new(0,5,0))
task.spawn(runningup)
end
end)
task.spawn(runningup)
Client-side script regarding the GUI:
local text = script.Parent
game.ReplicatedStorage.CountdownEvent.OnClientEvent:Connect(function(start,ending,increase)
for i = start,ending,increase do
text.Text = tostring(i)
task.wait(1)
end
game.ReplicatedStorage.StopEvent:FireServer(text.Text)
text.Text = "Play!"
end)
game.ReplicatedStorage.PlayingEvent.OnClientEvent:Connect(function(start,ending,increase)
for i = start,ending,increase do
text.Text = tostring(i)
task.wait(1)
end
game.ReplicatedStorage.RestartEvent:FireServer(text.Text)
text.Text = "Intermission or waiting for players.."
end)