Receiving an output that is literally impossible?

I’ve been receiving the output from my little server script and it just seems impossible what I’m getting. I’ve printed out nearly everything to just prove the fact that it has the player in the table, it identifies the player from the function, but the table.find() function is returning a nil value - as if its not in the table at all, as if it isn’t indexed at all. How? Why?

Code :

Players.PlayerRemoving:connect(function(player)
print(Dueling) -- Dueling table
print(player) -- The player that disconnected
local dude = table.find(Dueling, player) -- Finding index of disconnected player
print(dude) -- Check the index ( for some reason always nil )
if dude == nil then -- if dude is not in Dueling table, he is Participant
	print("Participants") 
else -- if he is in the index, hes a dueler.
	print("Dueling, i don't know")
end end)

Output :
22:31:09.564 ▼ {
[1] = “Player1”, – this is the dueling table
[2] = “Player2”
} - Server - main:23
22:31:09.564 Player1 - Server - main:24 – this is the player that disconnected
22:31:09.564 nil - Server - main:26 – this is trying to find the index of the player
22:31:09.564 Participants - Server - main:28 – this is the if statement return

Please any help at all with this topic is greatly appreciated as its really halted a lot of progress on the game.

I think this is due to the player object getting destroyed when they leave, try switching to player.UserId instead of player
Nevermind, are the values in the table player objects or player usernames? If they are usernames then table.find(Dueling, player.Name) should find it

2 Likes

The player object is not destroyed after all PlayerRemoving execution ? I am not sure

1 Like

You know what, I literally did .DisplayName and it still didn’t work- funny enough that worked. Annoying that it just wouldn’t work with player. Tisk tisk tisk, LuaU.

I don’t think you insert the actual player object into the table. Maybe you’re inserting tostring(player)? If you want it to work with the player object itself you would just do

table.insert(Dueling, player) -- not tostring(player) or player.Name