I have a script (inside of the seat) that will animate how a player sits for better effect, but when the player exits the seat the animation plays. Here's the script I'm using:
while true do wait() if script.Parent.Occupant ~= nil then print(script.Parent.Occupant.Name) track = Instance.new("Animation") track.AnimationId = "http://www.roblox.com/asset/? id=2982336649" local animationTrack = script.Parent.Occupant:LoadAnimation(track) animationTrack:Play() elseif script.Parent.Occupant == nil then if track ~= nil then track:Destroy() end end end
Any help would be appreciated, thanks. :)
Hello! I'm BlackOrange3343 and I'll be helping you today!
I sometimes have this problem and you simply have to do the opposite of :Play()
. There is a better way to write your script but I'm gonna copy paste because I'm at school right now.
while true do wait() if script.Parent.Occupant ~= nil then print(script.Parent.Occupant.Name) track = Instance.new("Animation") track.AnimationId = "http://www.roblox.com/asset/? id=2982336649" local animationTrack = script.Parent.Occupant:LoadAnimation(track) animationTrack:Play() elseif script.Parent.Occupant == nil then if track ~= nil then -- new portion below local animationTrack = script.Parent.Occupant:LoadAnimation(track) animationTrack:Stop() track:Destroy() end end end
Hopefully this helped!
Best of luck developer!
BlackOrange3343
PS: Try to use .Changed
instead of a loop, a loop is not a good way of doing this. Also you can load the animation outside of the loop and get it ready to be played and stopped. If this doesn't work notify me, it was some quick raw editing.