Provide an overview of:
- What does the code do and what are you not satisfied with?
Hello! So currently, I have a script that does the intermission, round, and goes back to the lobby. This cycle repeats forever. In the module, the script doesn’t necessarily wait until say the round is over to do the cleanup. - What potential improvements have you considered?
Having booleans that change values and then checking if those booleans were changed. - How (specifically) do you want to improve the code?
I would like to make the code determine whether or not a round has actually ended instead of waiting at a fixed number like 16 seconds before proceeding to the cleanup and starting the next intermission.
local mod = {}
local minimumPlayers = 1
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local Skydive = RemoteEvents:WaitForChild("Skydive")
function mod:Intermission(Players, Status, Intermission, IntermissionLength)
local function EnoughPlayers()
for i = 0, 3 do
Status.Value = "Waiting for more players to join"..string.rep(".", i)
task.wait(1)
end
end
repeat EnoughPlayers() task.wait() until #Players:GetPlayers() >= minimumPlayers
repeat task.wait() until #Players:GetPlayers() >= minimumPlayers
-- set the intermission value to true
Intermission.Value = true
for i = IntermissionLength, 0, -1 do
Status.Value = "Intermission: "..tostring(i)
task.wait(1)
end
Intermission.Value = false
end
function mod:StartRound(Players, Status, InProgress, Arena, TeleportTo)
-- start the round
InProgress.Value = true
Status.Value = "Round in progress!"
for i, player in pairs(Players:GetPlayers()) do
local Character = player.Character or player.CharacterAdded:Wait()
if Character then
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
player:SetAttribute("InRound", true)
if player:GetAttribute("InRound") then
HumanoidRootPart:PivotTo(TeleportTo.CFrame)
Skydive:FireClient(player)
end
end
end
end
task.wait(2)
Arena.BrickColor = BrickColor.random()
task.wait(2)
Arena.CanCollide = false
end
function mod:EndRound(Players, Status, Arena, Target, LobbySpawn, InProgress)
-- end the round
local Connection
local Winners = {}
local debounce = false
Target.Touched:Connect(function(Hit)
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
if not table.find(Winners, Player) then -- if it's not the same player.
table.insert(Winners, Player) -- then insert them into the table.
end
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character then
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
Player:SetAttribute("InRound", false)
HumanoidRootPart:PivotTo(LobbySpawn.CFrame + Vector3.new(0, 10, 0))
Arena.CanCollide = true
for i, winner in pairs(Winners) do
if table.find(Winners, Player) then -- checks if the player is a winner.
Status.Value = "Winner(s): "..winner.Name
Player.leaderstats["Glory Points"].Value += math.random(100, 200)
Player.leaderstats["Glory Coins"].Value += math.random(25, 50)
end
task.wait(1)
end
table.clear(Winners) -- clear the table of previous winners.
InProgress.Value = false
end
end
end
end)
end
function mod:Cleanup(Players, Status, Cleanup)
-- cleanup and wait for the next round
task.wait(16)
Cleanup.Value = true
for i = 0, 3 do
Status.Value = "Cleaning up"..string.rep(".", i)
task.wait(1)
end
Cleanup.Value = false
end
return mod