There are two different modes in my game: Free for all and Team Deathmatch.
Is there a way to use a module script or someone other way to shorten my code in my main game script?
Heres the Free for all part:
local ChosenGameMode = AvailableGameModes[math.random(1,#AvailableGameModes)]
Status.Value = "Choosing a GameMode!"
wait(1)
Status.Value = ChosenGameMode.Name
if ChosenGameMode.Name == 'Free-For-All' then
require(script.Parent.Parent.Parent.ServerStorage.GameModes.ModuleScript)
local plrs = {}
for i, player in pairs (game.Players:GetPlayers()) do
if (not player.IntroTag.Value) and (not player.AFK.Value) then
table.insert(plrs,player)--Add each players into plrs table
print(player)
print(#plrs)
else
warn(player, 'was not Inserted - AFK or Intro.')
print(#plrs)
end
end
wait(1)
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
Status.Value = "Choosing a Map..."
wait(3)
Status.Value = ChosenMap.Name.." Chosen"
wait(1)
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace
--[[ | |
| |
Teleport Players to Map
| |
| |
--]]
wait(1)
workspace.LobbyMusic.Intermission:Pause()
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
error("SpawnPoints not Found!")
end
pcall(function()
local AvailableSpawnPoints = SpawnPoints:GetChildren()
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
--Teleport Them
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,8,0)
table.remove(AvailableSpawnPoints,1)
--Give them a sword
local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
if equipped.Value ~= "" then
local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
weapon.Parent = player.Backpack
else
local Sword = ServerStorage.Sword:Clone()
Sword.Parent = player.Backpack
end
game.Workspace:FindFirstChildOfClass("Player")
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
--There is no Character
if not player then
table.remove(plrs,i)
end
end
end
end
end)
Status.Value = "Get Ready to Play!"
wait(3)
for i = GameLength,0,-1 do
for x, player in pairs(plrs) do
if player then
character = player.Character
if not character then
--left the game
table.remove(plrs,x)
else
if character:FindFirstChild("GameTag") then
--They are still alive
print(player.Name.." is still in the game!")
else
--They are dead
table.remove(plrs,x)
end
end
else
table.remove(plrs,x)
print(player.Name.." has been Removed!")
end
end
Status.Value = "Free-For-All|Time:"..i.."|Players:"..#plrs..""