Hello, this is one of the main modules in one of the server scripts inside my game although it’s gotten long. Is there any optimizations I could make to this module to shorten it? Any help is appreciated.
function module.SetupRound()
TransitionEvent:FireAllClients()
task.wait(1)
local RandomMap = math.random(1, #Maps)
local ChosenMap = Maps[RandomMap]:Clone()
ChosenMap.Parent = game.Workspace
RoundInfo.Status.Changed:Connect(function()
if RoundInfo.Status.Value == "Intermission" and ChosenMap then
ChosenMap:Destroy()
end
end)
local PlayerSelection = Players:GetPlayers()
local RandomPlayer = math.random(1, #PlayerSelection)
local ChosenPlayer = PlayerSelection[RandomPlayer]
local Character = Skins[ChosenPlayer.EquippedSkin.Value]:Clone()
ChosenPlayer.Status.Value = "Ashes"
ChosenPlayer.Character = Character
Character.Parent = game.Workspace
Animate.Parent = ChosenPlayer.Character
for _, Player in ipairs(Players:GetPlayers()) do
local PlayerSpawn = ChosenMap.Spawns:FindFirstChild("PlayerSpawn")
local AshesSpawn = ChosenMap.Spawns:FindFirstChild("AshesSpawn")
if Player.Status.Value ~= "Ashes" then
Player.Status.Value = "Round"
end
if Player.Status.Value == "Round" then
Player.Character:PivotTo(PlayerSpawn.CFrame)
elseif Player.Status.Value == "Ashes" then
Player.Character:PivotTo(AshesSpawn.CFrame)
end
end
end