Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help Problem With Round System (Really need help , please?) [Solved]

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

2 answers

Actually I Fixed it myself, I Checked If the player is in the Table first before removing lol, i dont know why it works how it works but it works and im content with it lol

1 comment

0

Can you post SOLVED in the title?

For Any Body Who Wants The Answer Just Use math.floor

Example:

local Decimal = 0.12123123123 -- Not Rounded

print(math.floor(Decimal))

Output:

0

This discussion is preserved as it was. New answers, comments, and votes are closed.