My script Isn't removing a player from a table when they get out of a seat. This script is intended to be a script where if a player sits in a seat they get added to a table and if they get up then they get removed.
local PlrSave = nil script.Parent.Seat:GetPropertyChangedSignal("Occupant"):Connect(function() if script.Parent.Seat.Occupant ~= nil then local Char = script.Parent.Seat.Occupant.Parent local player = players:GetPlayerFromCharacter(Char) local PlrSave = player table.insert(caroccupants, player) for i, v in pairs(caroccupants) do print(i) print(v) end else if PlrSave and PlrSave:IsA("Player") then -- possibly where it goes wrong, maybe not for i, v in pairs(caroccupants) do if v == PlrSave then -- this is not removing the player that was last sitting in the object "seat" table.remove(caroccupants, i) end end for i, v in pairs(caroccupants) do print(i) print(v) end end end end)
Here is the output
16:32:03.661 1 - Server - Script:36
16:32:03.661 hohoyoyo291 - Server - Script:37
-- when I sat in it the first time, also it is not printing anything here, maybe it is the
16:32:07.411 1 - Server - Script:36
16:32:07.411 hohoyoyo291 - Server - Script:37
16:32:07.411 2 - Server - Script:36 -- there should only be 1
16:32:07.412 hohoyoyo291 - Server - Script:37 -- it didn't remove this value