Remove From Table Without Number

image

I have two parts:

One part adds player to table on touch
Two part removes player to table on touch

The problem is that you must have index number of the thing to remove it, but I can’t do that

Remove:

TableRemove.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Head") and game.Players:FindFirstChild(hit.Parent.Name) then
		local p = game.Players:FindFirstChild(hit.Parent.Name)
		if table.find(PlayerTable,p) then
			table.remove(PlayerTable,p)
		end
	end
end)

Add:

TableAdd.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Head") and game.Players:FindFirstChild(hit.Parent.Name) then
		local p = game.Players:FindFirstChild(hit.Parent.Name)
		if not table.find(PlayerTable,p) then
			table.insert(PlayerTable,p)
		end
	end
end)
1 Like
TableRemove.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Head") and game.Players:FindFirstChild(hit.Parent.Name) then
		local p = game.Players:FindFirstChild(hit.Parent.Name)
		if table.find(PlayerTable,p) then
			table.remove(PlayerTable,table.find(PlayerTable,p))
		end
	end
end)
1 Like

If the item was found in the table, the method returns the element’s index.

2 Likes

This code worked for me thank you HugeCoolboy2007 and you for helping me

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