When the game starts there are two players. If there is one player alive the player should get credits and return to the lobby. But instead of that the timer continues and the player won't get any credits. Any solutions?
Here is the script
local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren() -- Make sure that your maps are in serverstorage. If you have more than just maps in serverstorage, the script might actually choose that. local chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)] chosenmap:Clone().Parent = mapstorage status.Value = "Loading Map.." wait(3) local spawns = chosenmap:WaitForChild('Spawns'):GetChildren() for _, player in pairs (game.Players:GetPlayers()) do if player and #spawns > 0 then local torso = player.Character:WaitForChild('HumanoidRootPart') 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 primary = game.ReplicatedStorage.Handgun -- CHANGE THIS TO WHATEVER ITEM YOU WANT TO GIVE THEM WHEN THEY ARE TELEPORTED. MAKE SURE IT IS IN REPLICATED STORAGE. local newprimary = primary:Clone() newprimary.Parent = player.Backpack end end end status.Value = "Be The Last Standing!" if status.Value then game.Workspace.Sound:Stop() end wait(4) for i = 196,0,-1 do -- You can adjust the #196 to how long you want the round to last. if i == 0 then status.Value = "Time is up!" wait(3) break end wait(1) if #_G.gameplayers == 1 then for i, v in pairs(_G.gameplayers) do if v ~= nil then status.Value = v.." Won The Game!" game.Players[v].leaderstats.Cash.Value = game.Players[v].leaderstats.Cash.Value + 15 -- The #15 will be how much credit or cash is awarded to the player if there was only one player teleported. break end end break else status.Value = i.."..Seconds Remaining!" end end for i, player in ipairs(game.Players:GetPlayers()) do if player.Character then local hum = player.Character:FindFirstChild('Humanoid') if hum then hum.Health = 0 end end end mapstorage:ClearAllChildren() wait(5) end
I think the problem is somewhere here but im not sure
if #_G.gameplayers == 1 then 36 for i, v in pairs(_G.gameplayers) do 37 if v ~= nil then 38 status.Value = v.." Won The Game!" 39 game.Players[v].leaderstats.Cash.Value = game.Players[v].leaderstats.Cash.Value + 15 -- The #15 will be how much credit or cash is awarded to the player if there was only one player teleported. 40 break 41 end 42 43 end 44 break 45 else 46 status.Value = i.."..Seconds Remaining!" 47 end 48 end 49 for i, player in ipairs(game.Players:GetPlayers()) do 50 if player.Character then 51 local hum = player.Character:FindFirstChild('Humanoid') 52 if hum then 53 hum.Health = 0 54 end 55 end 56 end