hello! im trying to get the player from a seat’s attribute. i stored an attribute in the seat called “playerName” so their name goes in there when they join and when they leave occupied is set to false and the playername is set to none but its not working. im not sure what to do so ty!
problem area:
function startGameModule.removePlayerfromChair()
game.Players.PlayerRemoving:Connect(function(p)
local getPlayer = randomSeat:GetAttribute("playerName")
if getPlayer ~= game.Players:FindFirstChild(getPlayer) then
randomSeat:SetAttribute("occupied", false)
randomSeat:SetAttribute("playerName", "")
end
end)
end
script:
function startGameModule.startGameFunction()
local plrCount = #game.Players:GetPlayers()
local seatOFFSET=CFrame.new(0,2,0)
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
local seatFolder = workspace.tableModel.seatFolder
local hum:Humanoid = c.Humanoid
randomSeat = seatFolder:GetChildren()[math.random(1, #seatFolder:GetChildren())]
if randomSeat:GetAttribute("occupied") == false then
c:PivotTo(randomSeat.CFrame* seatOFFSET)
wait()
randomSeat:Sit(hum)
if randomSeat.Occupant then
randomSeat:SetAttribute("occupied", true)
randomSeat:SetAttribute("playerName", randomSeat.Occupant.Parent.Name)
end
end
end)
end)
end
function startGameModule.removePlayerfromChair()
game.Players.PlayerRemoving:Connect(function(p)
local getPlayer = randomSeat:GetAttribute("playerName")
if getPlayer ~= game.Players:FindFirstChild(getPlayer) then
randomSeat:SetAttribute("occupied", false)
randomSeat:SetAttribute("playerName", "")
end
end)
end
occupied + playername is still there even when they left: