So I’m trying to make a custom sit animation for one of the seat in my game. The script works perfectly fine, there aren’t any errors showing up. But as soon as I sit down the animation stops and switches to the default sit animation. I haven’t found any solutions so far. Here is my script and a video of what’s happening.
local seat = script.Parent
local animation = script.Parent.sitanim
function added(child)
local hum = child.part1.Parent.Humanoid
local LoadedAnimation = hum:LoadAnimation(animation)
LoadedAnimation:Play()
end
function removed(child)
local hum = child.part1.Parent.Humanoid
local LoadedAnimation = hum:LoadAnimation(animation)
LoadedAnimation:Stop()
LoadedAnimation:Remove()
end
seat.ChildAdded:connect(added)
seat.ChildRemoved:connect(removed)
I have also just realised it’s not just doing it with the seat, it’s doing it when I walk and jump as well.
This can happen if your animation has a lower priority, weighting or isn’t looped. You could also just stop the default sitting animation from playing if a certain condition is met or overwrite it.
Worth also mentioning but your script has some issues too, both trivial and real. The trivial issue is that you’re using deprecated functions where you shouldn’t (Remove and lowercase connect), while the real issue is that the code won’t do what you think it will. Your added and removed function will both reference completely different animation tracks, so you aren’t stopping the original one in this case.
Both the added and removed functions should be referencing the same track. You can use a variable to track this, or more preferably use a LocalScript to control the animation if you aren’t doing so already because that’ll make it easier to establish a variable holding the loaded track that you can play and stop whenever the character enters or leaves the seat.