A friend made it for me a while ago, I tried giving it a go myself but didn't really turn out well, could somebody explain to me what needs to be done/why and show me what it should look like once fixed? Here's the script:
math.randomseed(tick()) -- services local teams = game:GetService("Teams"); local players = game:GetService("Players"); local lighting = game:GetService("ServerStorage"); -- teams local crims = teams:WaitForChild("Criminals"); local polis = teams:WaitForChild("Police"); local specs = teams:WaitForChild("Spectators"); -- maps -- I used a table in case you want to add more maps in the future: -- all you'll need to do is insert `` lighting:WaitForChild("Map Name"); `` local maps = { lighting:WaitForChild("Night Store"); lighting:WaitForChild("Verkauf's Mansion"); lighting:WaitForChild("Day Store"); }; -- to make life easier local function getCounts() return #crims:GetChildren(), #polis:GetChildren(); end; --[[ for the game ]]-- function connectDeath(player) local char = player.Character; -- wait for the character's humanoid to -- exist local humn = char:WaitForChild('Humanoid'); -- return the connection object return humn.Died:connect(function() player.TeamColor = specs.TeamColor; end); end; function assignRandomRole(player) local ccount, pcount = getCounts(); if ccount > pcount then player.TeamColor = polis.TeamColor elseif pcount > ccount then player.TeamColor = crims.TeamColor elseif ccount == pcount then local mraa = math.random(1,2); if mraa == 1 then player.TeamColor = crims.TeamColor elseif mraa == 2 then player.TeamColor = polis.TeamColor end end return player.TeamColor; end; --[[--------------]]-- while wait(1) do -- local variables are faster, -- however not always appropriate local msg = Instance.new("Hint") local rand = math.random(1,2) -- necessary for the game local ccount, pcount = getCounts(); local connections = { }; if #players:GetPlayers() > 1 then msg.Parent = workspace; msg.Text = 'The game is about to start!'; wait(5); -- Find a map in the "maps" table with a -- random index # ranging from 1 to the -- number of given maps local mc = maps[math.random(1, #maps)]; local pbase = workspace.policestation; local cbase = workspace.criminalhideout; -- Spawn locations for each team local p_spawns = pbase.spawns:GetChildren(); local c_spawns = cbase.spawns:GetChildren(); mc.Parent = game.Workspace local mapspawn = workspace:findFirstChild("mapmat"); mc:MoveTo(Vector3.new(mapspawn.Position.X, mapspawn.Position.Y/2, mapspawn.Position.Z)) msg.Parent = game.Workspace msg.Text = "The map " .. mc.Name .. " has been chosen." -- assign each player a role and connect the event -- that neutralizes them when they are done for _, player in pairs(players:GetChildren()) do assignRandomRole(player); table.insert(connections, connectDeath(player)); local translation = Vector3.new(math.random(-3, 3), 3, math.random(-3, 3)); if player.TeamColor == crims.TeamColor then local spawn = c_spawns[math.random(1,#c_spawns)]; player.Character:WaitForChild('Torso').CFrame = spawn.CFrame+translation elseif player.TeamColor == polis.TeamColor then local spawn = p_spawns[math.random(1,#p_spawns)]; player.Character:WaitForChild('Torso').CFrame = spawn.CFrame+translation end end; wait(3); msg.Parent = nil; -- don't destroy it, we still need it! -- wait until theres no players left on either team -- by repeatidly getting the count of the teams -- and checking to see if one equals zero -- (this updates the variables until done) repeat wait(1); ccount, pcount = getCounts(); until ccount==0 or pcount==0; msg.Parent = game.Workspace -- if the count of police = 0 then -- or if the count of criminals = 0 then if pcount == 0 then msg.Text = "The Criminals have won!" elseif ccount == 0 then msg.Text = "The Police have won!" end; -- neutralize all players for _, player in pairs(players:GetChildren()) do player.TeamColor = specs.TeamColor; end; -- disconnect all connections for i, connection in next, connections do connection:disconnect(); end; wait(3) msg:Destroy() mc:Destroy() else msg.Parent = workspace msg.Text = "You need 2 or more people to start the game." wait(3); msg:Destroy(); end end
The idea of it is to equally split the players into the Criminals/Police teams, select a random map, teleport the players to the team spawns. when all of one team dies the other is crowned as winners OR if the time runs out (5 minutes) it ends as a draw. Then players will be changed to the spectator team and killed starting the game again after a minute of being in the lobby Here's the information you'd need for the script to make sense:
lobbyspawns (model) > spawn1 to spawn10
criminalhideout (model) > spawns (model) > spawn1 to spawn5
policestation (model) > spawns (model) > spawn1 to spawn5
mapmat
If you need more information, let me know. If you help, thank you:)
Line 81 should be changed so that it creates a clone of the map instead of using the prototype, because on line 147 you're destroying it.