So I have this script that when player2 accepts an invite from player1 they are added into a table in a local script in player1. What I want to achieve is when player2 triggers a proximity prompt they will be removed from the table however I cannot seem to understand why any method I use to find the player in the table including table.find, playersInHouse[player2], or some other nonsense, never finds the player. When the players are inserted into the table they are player instances.
for i, PromptPart in pairs(CollectionService:GetTagged("PropertyExitPrompts")) do
local Proxy = PromptPart.ProximityPrompt
Proxy.Triggered:Connect(function(PlayerWhoTriggered: Player)
if PlayersInHouse[PlayerWhoTriggered] then
print("found")
else
print("not found")
end
end)
end
when I print the table, the player is in there so its not like theyre not being added
Then you have to change how you’re indexing the table. Since the table is an Array, when you index it like PlayersInHouse[PlayerWhoTriggered], you’re trying to get the value that has the index set to a player instance.
Change that line to this:
local foundPlayer = false
for _, player in PlayersInHouse do -- Loops through the table
if player == PlayerWhoTriggered then -- Checks if a player value in the table is equal to the triggered player
foundPlayer = true -- If it is, then we found the player
end
end
print(foundPlayer)