And my script is suppost to delete both of them once the seats occupant == nil, but it isnt
local sitAnim = 18201895983
local seat = script.Parent
local playingAnim
local newAnim = Instance.new('Animation')
newAnim.AnimationId = 'rbxassetid://'..sitAnim
seat.Changed:Connect(function(property)
if property == 'Occupant' then
local occupant = seat.Occupant
if not occupant then if playingAnim then playingAnim:Stop() return end end
playingAnim = occupant:LoadAnimation(newAnim)
playingAnim:Play()
end
if script.Parent.Occupant == nil then
local player = game:GetService("Players"):FindFirstChildOfClass("Player")
local character = player.Character
local rightHand = character:WaitForChild("RightHand")
if rightHand:WaitForChild("BasicBenchPressWeights", 10000000000000000000000) then
rightHand.BasicBenchPressWeights:Destroy()
rightHand.BenchpressMotor6D:Destroy()
end
end
end)
Well first of, when going on it and it finds the Occupant, then it sets the PlayingAnim. But the problem is, if you exit then it returns the whole Function because it founds no occupant but a playinganim. And also, the local player is bad, since it will find someone that is the first child in the Players Folder. So it will never get the player who just stepped out.
local lastoccupant = nil
seat.Changed:Connect(function(property)
if property == 'Occupant' then
if seat.Occupant then
local lastoccupant = seat.Occupant
playingAnim = lastoccupant:LoadAnimation(newAnim)
playingAnim:Play()
else
if lastoccupant then else return end
local character = lastoccupant.Parent
local rightHand = character:WaitForChild("RightHand")
if rightHand:WaitForChild("BasicBenchPressWeights", 10000000000000000000000) then
rightHand.BasicBenchPressWeights:Destroy()
rightHand.BenchpressMotor6D:Destroy()
end
lastoccupant = nil
end
end
end)