Im so confused on table.remove()

so im makng a round system and i have 3 tables alive, dead, finished and when the player fails there userid is meant to remove that from the table the code here

local RoundSerivce = {}

local Waitime = "15"
local LeastPlayers = 1
local TeleportationPart = workspace.Teleportation
local ColourPickerSerivce = require(game:GetService("ReplicatedStorage").Serivces.ColourPickerSerivce)
local Players = game.Players
local Alive = {}
local Dead = {}
local Finshed = {}
local RoundInProgess = false
local RoundHASStarted = false
local NEP = "Not Enough Players!"
local SI =  "Intermisson: "
local RoundStarting = game.ReplicatedStorage.Remotes:FindFirstChild("RoundStarting")
local TimeWaiting = 1
local IntermissonTime = 5


function Count()
	local Playerrs = 0
	for i,v in Players:GetPlayers() do
		Playerrs += 1
	end
	return Playerrs
end

function GrabPlayers()
	local PLayer 
	for i,plr in pairs(Players:GetPlayers()) do
		table.insert(Alive,plr.UserId)
		PLayer = plr
	end
	return PLayer
end

function InGame(Player: Player)
	local DB = false
	local function BaseTouched(hit: Instance)
		if hit.Parent.Humanoid and DB == false then
			DB = true
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			table.remove(Alive,plr.UserId)
			table.insert(Dead,plr.UserId)
			hit.Parent:PivotTo(game.Workspace.SpawnLocation.CFrame + Vector3.new(0,5,0))
			print("Removed")
	
task.wait(.2)
			DB = false
			local number = 0
			for i,v in Alive do

				if Players:GetPlayerByUserId(v) then
					local p = Players:GetPlayerByUserId(v)
					print(p.Name)
					number += 1

				end
			end
			print(number)

			if number == 0  then
				workspace.Baseplate:SetAttribute("OutOfPlayers",true)
			end

		end
		
	end
	local function FinshTouched(hit: Instance)
		if hit.Parent.Humanoid and DB == false then
			DB = true
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			if table.find(Alive,plr.UserId) then
				print("successs")
			
			table.remove(Alive,plr.UserId)
			table.insert(Finshed,plr.UserId)
			local Awarder =require( game.ReplicatedStorage.Serivces.StatsAwarderSerivce)
			Awarder.Touched(hit)
			print("added")
			task.wait(.2)
			DB =false
			end
		end
	end
	workspace.GiverParts.Awrder.Touched:Connect(FinshTouched)
	workspace.Baseplate.Touched:Connect(BaseTouched)
end



function RoundSerivce.StartTime(Player: Player)
	task.wait(2)
	local Count2 = Count()
	if Count2 >= LeastPlayers then
		print("starting")
		RoundHASStarted = true
		RoundStarting:FireAllClients(SI,2)
		while TimeWaiting ~= IntermissonTime do
			local NewCount = Count()
			if NewCount < LeastPlayers then
				RoundHASStarted = false
				RoundStarting:FireAllClients(NEP,"2")
				break
			end
			TimeWaiting += 1
			task.wait(1)
			end
		
		TimeWaiting = 1
		local Plr  = GrabPlayers()
		Plr.Character:PivotTo(TeleportationPart.CFrame + Vector3.new(Random.new(-20,20),Random.new(0,20),0))
		print("Round Starting")
		InGame(Player)
		
	else 
	print( "Not Enough Players!")
	end
end

function RoundSerivce.ClentSide(Message,Type)
	local Player = game:GetService("Players").LocalPlayer
	if typeof(Type) == "number" then
		for i = IntermissonTime,1,-1 do
			print(i)
			Player.PlayerGui.Main.Anocher.Countdown.Text = Message..i
			task.wait(1)
		end
		Player.PlayerGui.Main.Anocher.Countdown.Text = "Round In Progress!"

	elseif typeof(Type) == "string" then
		Player.PlayerGui.Main.Anocher.Countdown.Text = Message

	
	end
end




return RoundSerivce

so please help if you can

The second parameter of table.remove() is the index of the value to remove, not the value itself.

The simplest way to get around this is to simply do

table.remove(TABLE, table.find(TABLE, VALUE)\)

for example, in your code:

table.remove(Alive,plr.UserId)

would become

table.remove(Alive, table.find(Alive, plr.UserId))

yes thank you it works now and now i unstand a bit more about tables

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.