Player is killed even though he is in the table

I want to make a musical chairs system, and kill the player who does not get a seat.

However, there’s a weird problem. When testing it with multiple clients, if “Player1” sits down, he is killed even though he has sat down and is in the table, but when “Player2” sits down, he is not killed.

There’s been nothing that I’ve found that has helped me.

Code:

local function selectSeats(chair, otherPart)
	print(otherPart)
	local character = otherPart
	local player = Plrs:GetPlayerFromCharacter(character)

	if player and not seatedPlayers[player] then
		table.insert(seatedPlayers,player)
		print(player.Name .. " has taken a seat")
		player.Character.HumanoidRootPart.Anchored = true
		print(#seatedPlayers .. " players are seated")

		if #seatedPlayers == #Plrs:GetPlayers() - 1 then
			for _, p in ipairs(Plrs:GetPlayers()) do
				if not seatedPlayers[p] then
					print(p.Name .. " is eliminated")
					p.Character.Humanoid.Health = 0
					break
				end
			end
		end
	end
end

I provided a snippet of my code which should be enough. Any help appreciated!

You’re using p as the index instead of a number. Try:

if not table.find(seatedPlayers, p) then
3 Likes

That worked! Thank you very much. I’m just wondering though, why would it work for a different player, but not work for the 1st player?

1 Like

seatedPlayers[p] would return nil, so not seatedPlayers[p] would be true.

1 Like

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