I am making a FPS (First Person Shooter), but the problem is, when the intermission gets to 0, it only teleports one of the players, I have no idea why this is, here is the code!
local rs = game:GetService("ReplicatedStorage")
local status = rs:WaitForChild("StatusValue")
while true do
while game.Players.NumPlayers < 2 do
status.Value = "There needs to be two more players to start the game!"
repeat wait(2) until game.Players.NumPlayers >= 2
end
for i = 30, 0,-1 do
status.Value = "Intermission: "..i
wait(1)
end
_G.gameplayers = {}
for i, v in pairs(game.Players:GetPlayers()) do
if v then
table.insert(_G.gameplayers, v.Name)
end
end
local spawns = workspace:WaitForChild('Spawns'):GetChildren()
for _, player in pairs(game.Players:GetPlayers()) do
if player and #spawns > 0 then
local torso = player.Character:WaitForChild('Torso')
local allspawns = math.random(1, #spawns)
local randomspawn = spawns[allspawns]
if randomspawn and torso then
table.remove(spawns, allspawns)
torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
local gun = game.ReplicatedStorage["MP40"]:Clone()
gun.Parent = player.Backpack
end
end
end
while true do
wait(1)
if #_G.gameplayers == 1 then
for i, v in pairs(_G.gameplayers) do
if v ~= nil then
status.Value = v.. ' is the winner! Well done!'
game.Players[v].leaderstats.cash.Value = game.Players[v].leaderstats.cash.Value + 10
break
end
end
break
else
status.Value = "Match in Progress"
end
end
wait(5)
end
