I am trying to achieve their sitting animation system how every seat has a different animation and my first try went well until it got to the point I needed to remove or stop the animation, the animation doesn’t stop when I jump out of the seat.
The animation is set to idle in priority and is looped.
Here is the script:
local seat = script.Parent
seat.ChildAdded:Connect(function(child)
if (child.ClassName == "Weld") then
local human = child.part1.Parent:FindFirstChild("Humanoid")
if human ~= nil then
local anim = human:LoadAnimation(seat.sitanim)
anim:Play()
end
end
end)
seat.ChildRemoved:Connect(function(child)
if seat.sitanim then
seat.sitanim:Destroy()
wait()
local newanim = Instance.new("Animation",seat)
newanim.Name = "sitanim"
newanim.AnimationId = "rbxassetid://6435284432"
end
end)
This is the explorer:
This is what it looks like on a seat:
This is what happens when you get off:
It only tells me this but I don’t know what to do with it:
LoadAnimation returns an entirely separate instance called an AnimationTrack which is the instance actually playing the Animation, you should be stopping that instead of deleting the Animation itself.
This doesn’t fix anything, sitanim is an animation located in the seat, I sent an image of the explorer panel and it clearly shows the animation in the seat.
It’s nil and it’s parent is locked, but you could have it as a variable outside of the two connections, and reference the track like you did with anim.
local seat = script.Parent
local anim
seat.ChildAdded:Connect(function(child)
if (child.ClassName == "Weld") then
local human = child.part1.Parent:FindFirstChild("Humanoid")
if human ~= nil then
anim = human:LoadAnimation(seat.sitanim)
anim:Play()
end
end
end)
seat.ChildRemoved:Connect(function(child)
anim:Stop()
anim = nil
--Might not be needed, but just in case
--[[seat.sitanim:Destroy()
wait()
local newanim = Instance.new("Animation",seat)
newanim.Name = "sitanim"
newanim.AnimationId = "rbxassetid://6435284432"]]
end)
Something like this. I would have done better but I’m on mobile for now.