local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AntiCheatFolder = ReplicatedStorage:WaitForChild("AntiCheat")
local Announce = AntiCheatFolder.Announce
local GameStatus = ServerStorage.GameStatus
local Players = game.Players
local GameSpawns = workspace.GameSpawns
local TimePerRound = 90
local Intermission = 6
GameStatus.Value = false
local PlayersInGame = {}
while wait() do
PlayersInGame = {}
GameStatus.Value = false
for i,plr in pairs(Players:GetChildren()) do
local PlrChar = plr.Character
if PlrChar then
local PlrHum = PlrChar:FindFirstChild("HumanoidRootPart")
PlrHum.CFrame = workspace.SpawnLocation.CFrame * CFrame.new(0,2,0)
end
end
for i = 1 , Intermission do
wait(1)
local TimeRemaining = Intermission - i
Announce:FireAllClients("Intermission : " .. TimeRemaining)
end
local IsEnoughPlayers = false
if #Players:GetPlayers() >= 2 then
IsEnoughPlayers = true
else
IsEnoughPlayers = false
Announce:FireAllClients("Not Enough Players")
wait(2)
end
if IsEnoughPlayers == true then
GameStatus.Value = true
-- the main problem of the question
for i,v in pairs(Players:GetPlayers()) do
local PlrCharacter = v.Character
local PlrStatus = v.PlrStatus.InGame
if PlrCharacter then
table.insert(PlayersInGame,v)
PlrStatus.Value = true
local RandomNumber = math.random(1,4)
local ChosenSpawn = GameSpawns:FindFirstChild(RandomNumber)
local PlrHMR = PlrCharacter:FindFirstChild("HumanoidRootPart")
PlrHMR.CFrame = ChosenSpawn.CFrame * CFrame.new(0,2,0)
local PlayerHum = PlrCharacter:FindFirstChild("Humanoid")
PlayerHum.HealthChanged:Connect(function(health)
if health <= 0 then
table.remove(PlayersInGame,table.find(PlayersInGame,v))
print(#PlayersInGame) -- If theres 3 player, and someone dies it print 1 then 0, if theres 4 it prints 2 then 1 then 0
PlrStatus.Value =false
end
end)
end
end
local TimeRemaining = TimePerRound
while TimeRemaining > 0 do
Announce:FireAllClients("Time Remaining : " .. TimeRemaining)
wait(1)
TimeRemaining = TimeRemaining - 1
print(#PlayersInGame) -- Prints how many player there are but if someone dies it prints 0, meaning every value in the table dissapear
if #PlayersInGame == 1 then
Announce:FireAllClients("The Winner Is " .. tostring(PlayersInGame[1]))
wait(2)
break
end
end
end
end
Hi, The Main Problem is in the script, the For i ,v in loops This is a round system, And the problem is if someone dies, All The Value in "PlayersInGame" Table Get Removed, It Should Only Remove Those Whoever Dies but For Some Reason It Removes all the value, Anyone help? i think The problem is The "In pairs" loop,
I been Sweating for Hours trying to fix this problem but i cant, so i asked help in discord but no one answers :( , now im going to ask here, Help will be aprreciated >:0

1 comment
Can you post SOLVED in the title?