Script doesn't remove object from list

It prints out the line “succesfully removed player from the table” However it doesn’t actually remove the player from the table

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	local plrId = game.Players:GetUserIdFromNameAsync(plr.Name)
	local char = game.Workspace[plr.Name]
	
	if table.find(playersInTable,plrId) then
		table.remove(playersInTable,plrId)
		print("succesfully removed player from table!")
		plr:LoadCharacter()
	
		
	else
		if not table.find(playersInTable,plrId) then
			table.insert(playersInTable,plrId)
			print("Succesfully added player in the table!")
			for i, spawnPoint in pairs(spawns) do
				char:FindFirstChild("HumanoidRootPart").CFrame = spawnPoint.CFrame
				char:FindFirstChild("HumanoidRootPart").Anchored = true
				table.remove(spawns,i)
			end

		end
	end
	
	
	
	
	
end)

Thanks in advance

Try using the example provided above, let me know if it doesn’t work.

Edit:

Do you need need this? Maybe change this to plr.UserId

1 Like

Hey, thanks it worked. Would you mind explain it to me why my code doesn’t work and ur code works?

When removing something from a table you require the index to remove it and not the actual value. For example you have 2 things stored in your table and you only want to remove the first one, you would do table.remove(tblName,1).

1 Like