-- Vars
local timer = 10 * 60
local intermissiontimer
-- Resources Needed
local ss = game:getService("ServerStorage")
local rs = game:getService("ReplicatedStorage")
local debris = game:getService("Debris")
local workspace = game.workspace
local event = rs:WaitForChild("RemoteEvent")
local maps = ss:WaitForChild("Maps")
local mapholder = workspace:WaitForChild("MapHolder")
GameStatus = "Loading Map"
Infected = {}
Humans = {}
-- Main game loop
while true do
mapholder:ClearAllChildren()
wait(2)
local activemaps = maps:GetChildren()
local nextmap = activemaps[math.random(1, #activemaps)]
nextmap.Parent = mapholder
wait(2)
GameStatus = "Waiting for Players"
while true do
wait(5)
Players = {}
for _, player in pairs(game.Players:GetPlayers()) do
if player and player.Character then
local humanoid = player:FindFirstChild("Humanoid")
if humanoid then
table.insert(Players, player)
end
end
if #Players >= 2 then
break
else
end
end
GameStatus = "Choosing Teams"
TempInfect = Players[math.random(1, #Players)]
TempInfect.TeamColor = BrickColor.new(1020)
table.insert(Infected, TempInfect)
for _, player in pairs(game.Players:GetPlayers()) do
if player ~= TempInfect then
table.add(Humans, player)
end
end
for _, player in pairs(game.Players:GetPlayers()) do
if player == Infected then
local humanoid = player:WaitForChild("Humanoid")
if humanoid then
humanoid.Health = 0
local backpack = player:FindFirstChild("Backpack")
if backpack then
local InfectedSword = ss:FindFirstChild("LinkedSword"):clone()
InfectedSword.Parent = player
end
end
else
local spawns = nextmap:WaitForChild("HumanSpawn"):GetChildren()
local spawnindex = math.random(1, #spawns)
local spawn = spawnindex[spawns]
local torso = player.Character:FindFirstChild("Torso")
if torso and spawn then
table.remove(spawn, spawnindex)
torso.CFrame = CFrame.new(spawn.Postion + Vector3.new(0, 3, 0))
local backpack = player:FindFirstChild("Backpack")
if backpack then
local HumanSword = ss:FindFirstChild("Sword"):clone()
HumanSword.Parent = backpack
end
end
end
end
end
wait(1)
end
✓ ANSWER ACCEPTED
Telporting isn't working. Not sure about Map Loading. Why?
1 answer
✓ Accepted answer
Line 74-75:
local spawnindex = math.random(1, #spawns)
local spawn = spawnindex[spawns]
Pretty sure you intended that to be:
local spawnindex = math.random(1, #spawns)
local spawn = spawns[spawnindex]
This discussion is preserved as it was. New answers, comments, and votes are closed.
