Hey! So I am making a Garry’s Mod inspired game called “Simon’s Sandbox”, and will have multiple gamemodes. Two of them being a “Trouble in Traitor Town” gamemode, and “The Anomaly” gamemode.
I am currently in the process of making a round system though I do not know if this code is sustainable enough or proper. Could someone give me feedback?
Thanks!
function loadCharacters()
local Players = game.Players:GetPlayers()
for _, player in pairs(Players) do
player.Team = game.Teams["Neutral"]
if player.Character == nil then
player:LoadCharacter()
end
end
end
function teleportTo()
local Players = game.Players:GetPlayers()
local Agents = Teams.Agent:GetPlayers()
local NeutralPlayers = Teams.Neutral:GetPlayers()
for i, v in pairs(NeutralPlayers) do
v.Character.HumanoidRootPart.CFrame = workspace:FindFirstChild("Agent").CFrame
end
end
function sortTeams()
canJoin.Value = true
print(canJoin.Value)
loadCharacters()
wait(5)
canJoin.Value = false
print(canJoin.Value)
teleportTo()
local Players = game.Players:GetPlayers()
local NeutralPlayers = Teams.Neutral:GetPlayers()
if #Players == 12 then
local index = math.random(3, #Players)
Players[index].Team = Teams["Anomaly"]
Players[index].Character.HumanoidRootPart.CFrame = workspace:FindFirstChild("Anomaly").CFrame
table.remove(NeutralPlayers, index)
elseif #Players >= 8 and #Players < 12 then
local index = math.random(2, #Players)
Players[index].Team = Teams["Anomaly"]
Players[index].Character.HumanoidRootPart.CFrame = workspace:FindFirstChild("Anomaly").CFrame
table.remove(NeutralPlayers, index)
elseif #Players >= 2 and #Players < 8 then
local index = math.random(1, #Players)
Players[index].Team = Teams["Anomaly"]
Players[index].Character.HumanoidRootPart.CFrame = workspace:FindFirstChild("Anomaly").CFrame
table.remove(NeutralPlayers, index)
end
for i, player in ipairs(NeutralPlayers) do
player.Team = Teams["Agent"]
end
roundStarted.Value = true
local mainTimer = roundTime
while mainTimer > 0 do
wait(1)
mainTime -= 1
local anomalyActive = false
local agentsActive = {}
for _, agent in pairs(Teams.Agent:GetPlayers()) do
if agent then
table.insert(agentsActive, agent)
end
end
for _, anomaly in pairs(Teams.Anomaly:GetPlayers()) do
if anomaly then
anomalyActive = true
end
end
if #agentsActive < 1 then
for _, anomaly in pairs(Teams.Anomaly:GetPlayers()) do
print("give anomaly something idk reward")
end
mainTimer = 0
break
end
if not anomalyActive then
for _, agent in pairs(Teams.Agent:GetPlayers()) do
print("give agents something idk reward")
end
mainTimer = 0
end
end
roundTime = 0
roundStarted.Value = false
end
while true do
local skip = false
while intermission > 0 do
local Players = game.Players:GetPlayers()
if #Players >= 2 then
intermission = intermission - 1
print(intermission)
wait(1)
else
while #Players < 2 do
Players = game.Players:GetPlayers()
wait(1)
end
skip = true
intermission = 0
end
end
wait(1)
if skip == false then
sortTeams()
while roundTime > 0 do
wait(1)
end
end
skip = false
intermission = 10
roundTime = 25
end