How to remove player from table easily

How would i remove a player from a table quickly in my script?

–Heres The Script

local playeruse = false

local tool = game.ReplicatedStorage.BluePrint:Clone()
local user

local PlayerTable = {}
local function PlrAdded (plr)
	task.wait(1)
	PlayerTable[#PlayerTable+1] = plr
	if playeruse == false then
		user = plr.UserId
		local char = plr.Character or plr.CharacterAdded:Wait()
		print("check")
		tool.Parent = char
		playeruse = true
	end
end


local function playerRemoved(plr)
	if user == plr.UserId then
		table.remove(?)
		user = nil
		playeruse = false
		print("check")
		for _, player in pairs(game.Players:GetChildren()) do
			local randPlayer = math.random(1, #PlayerTable)
			local char = randPlayer.Character or randPlayer.CharacterAdded:Wait()
			tool.Parent = char
		end
	end
end


game.Players.PlayerRemoving:Connect(playerRemoved)
game.Players.PlayerAdded:Connect(PlrAdded)
1 Like

Use the table.remove() function:

table.remove(PlayerTable, table.find(PlayerTable, plr))

You are required to use table.find() as the second argument as table.remove() takes in an index not the value as the second parameter.

Hope this helps!

2 Likes

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