so i have this round system in place and when i test it with a local server, it just gives player2 the win sometimes. any fixes??
script:
ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
teams = game:GetService("Teams")
DataStoreService = game:GetService("DataStoreService")
CashDataStore = DataStoreService:GetDataStore("cashDataStore")
Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
RoundStatus = ReplicatedStorage:WaitForChild('RoundStatus')
local Survivors = {}
while true do
if #game.Players:GetPlayers() >= 2 then
--Intermission
local Countdown = 5
repeat wait(1)
Countdown = Countdown - 1
RoundStatus.Value = 'Intermission : '..Countdown
until Countdown <= 0
--Choose the map.
RoundStatus.Value = 'Choosing minigame..'
local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
wait(3)
RoundStatus.Value = ChosenMap.Name.." has been chosen!"
wait(3)
ChosenMap.Parent = workspace
RoundStatus.Value = 'Teleporting players..'
wait(1)
--teleport the players
local Players = game.Players:GetPlayers()
for _, Player in pairs(game.Players:GetPlayers())do
if Player.Character and Player.Character:FindFirstChild('Humanoid') then
local RandomSpawn = Spawns[math.random(1, #Spawns)]
Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
Player.TeamColor = BrickColor.new("Persimmon")
Player.Character.Humanoid.MaxHealth = 100
Player.Character.Humanoid.Health = 100
Player.Character.Humanoid.WalkSpeed = 16
Survivors[Players] = true
end
end
local Countdown = 180
for i = Countdown, 0, -1 do
RoundStatus.Value = "Game In Progress: "..i
wait(1)
local Survivor = game.Teams.Playing
if #Survivor:GetPlayers() == 1 then
for i,v in pairs(game.Teams["Playing"]:GetPlayers()) do
RoundStatus.Value = v.Name.. " has won!"
v.leaderstats.Cash.Value = v.leaderstats.Cash.Value + 5
for _, Player in pairs(game.Players:GetChildren())do
if Player.Character and Player.Character:FindFirstChild('Humanoid') then
Player.Character.Humanoid:TakeDamage(9999999999)
end
end
wait(5)
ChosenMap:Destroy()
RoundStatus.Value = 'Round over!'
wait(1)
end
break
end
wait(1)
end
else
local dots = "..."
repeat
for i = 1,3 do
RoundStatus.Value = "Waiting For Players"..string.sub(dots, 1, i)
wait(1)
end
until #game.Players:GetPlayers() >= 2
end
end
Also, just looked at it again, it could be that the player doesn’t have a character yet so it doesn’t add them to the team.
And no no, I quoted your code, I was saying to do ipairs() instead of pairs(). But I think the problem is that the player doesn’t have a character yet.