local H=game:GetService("\080\108\097\121\101\114\115")local u=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local z=require((u:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\083\101\114\118\101\114\083\099\114\105\112\116\083\101\114\118\105\099\101"))local A=Instance.new("\070\111\108\100\101\114")A.Name="\071\097\109\101\083\116\097\116\101"A.Parent=u local Z=Instance.new("\070\111\108\100\101\114")Z.Name="\071\097\109\101\082\101\112\108\105\099\097\116\105\111\110"Z.Parent=u for H,u in pairs((z:GetResource("\083\101\114\118\105\099\101")):GetChildren())do z:GetResource("\083\101\114\118\105\099\101\046"..u.Name)end local W=z:GetResource("\083\101\114\118\105\099\101\046\073\110\118\101\110\116\111\114\121\083\101\114\118\105\099\101")W:LoadCharacterAssets()local s=z:GetResource("\083\101\114\118\105\099\101\046\078\080\067\083\101\114\118\105\099\101")s:LoadNPCModels()local V=z:GetResource("\083\101\114\118\105\099\101\046\067\104\097\114\097\099\116\101\114\083\101\114\118\105\099\101")local U=z:GetResource("\083\101\114\118\105\099\101\046\067\111\109\112\108\105\097\110\099\101\083\101\114\118\105\099\101")local d=z:GetResource("\083\101\114\118\105\099\101\046\080\108\097\121\101\114\068\097\116\097\083\101\114\118\105\099\101")local f=z:GetResource("\083\101\114\118\105\099\101\046\081\117\101\115\116\083\101\114\118\105\099\101")local v=z:GetResource("\083\101\114\118\105\099\101\046\077\097\112\068\105\115\099\111\118\101\114\121\083\101\114\118\105\099\101")local B=z:GetResource("\083\101\114\118\105\099\101\046\069\110\101\114\103\121\083\101\114\118\105\099\101")local function R(H)d:LoadPlayer(H)U:LoadPlayer(H)f:LoadPlayer(H)W:LoadPlayer(H)V:SpawnCharacter(H)v:LoadPlayer(H)B:LoadPlayer(H)end local function g(H)v:ClearPlayer(H)f:ClearPlayer(H)W:ClearPlayer(H)U:ClearPlayer(H)d:ClearPlayer(H)end H.PlayerAdded:Connect(R)H.PlayerRemoving:Connect(g)for H,u in pairs(H:GetPlayers())do(coroutine.wrap(function()R(u)end))()end
--[[
TheNexusAvenger

Runs the game.
--]]

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerScriptServiceProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ServerScriptService"))



--Create the folders.
local GameState = Instance.new("Folder")
GameState.Name = "GameState"
GameState.Parent = ReplicatedStorage

local GameReplication = Instance.new("Folder")
GameReplication.Name = "GameReplication"
GameReplication.Parent = ReplicatedStorage

--Initialize the services.
for _,ServiceModule in pairs(ServerScriptServiceProject:GetResource("Service"):GetChildren()) do
    ServerScriptServiceProject:GetResource("Service."..ServiceModule.Name)
end

--Initialize the resources before loading players.
--These resources are required by the players on join.
local InventoryService = ServerScriptServiceProject:GetResource("Service.InventoryService")
InventoryService:LoadCharacterAssets()

--Load the NPC models. Can't be saved directly
--to a model file and imported with Rojo.
local NPCService = ServerScriptServiceProject:GetResource("Service.NPCService")
NPCService:LoadNPCModels()

--Get the services.
local CharacterService = ServerScriptServiceProject:GetResource("Service.CharacterService")
local ComplianceService = ServerScriptServiceProject:GetResource("Service.ComplianceService")
local PlayerDataService = ServerScriptServiceProject:GetResource("Service.PlayerDataService")
local QuestService = ServerScriptServiceProject:GetResource("Service.QuestService")
local MapDiscoveryService = ServerScriptServiceProject:GetResource("Service.MapDiscoveryService")
local EnergyService = ServerScriptServiceProject:GetResource("Service.EnergyService")



--[[
Handles a player being added.
--]]
local function PlayerAdded(Player)
    PlayerDataService:LoadPlayer(Player)
    ComplianceService:LoadPlayer(Player)
    QuestService:LoadPlayer(Player)
    InventoryService:LoadPlayer(Player)
    CharacterService:SpawnCharacter(Player)
    MapDiscoveryService:LoadPlayer(Player)
    EnergyService:LoadPlayer(Player)
end

--[[
Handles a player being removed.
--]]
local function PlayerRemoved(Player)
    MapDiscoveryService:ClearPlayer(Player)
    QuestService:ClearPlayer(Player)
    InventoryService:ClearPlayer(Player)
    ComplianceService:ClearPlayer(Player)
    PlayerDataService:ClearPlayer(Player)
end



--Set up players joining.
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoved)
for _,Player in pairs(Players:GetPlayers()) do
    coroutine.wrap(function()
        PlayerAdded(Player)
    end)()
end