Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Remove an animation after a player is finished sitting in a seat?

Asked by 5 years ago

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. :)

1
you could use the GetPropertyChangedSignal method instead of a loop. hellmatic 1523 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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.

0
It didn't work but I gave it a few edits, thanks for the help! CaptainAlien132 225 — 5y
0
np BlackOrange3343 2676 — 5y
0
Also I was wondering how I would used the .Changed, whenever I try to use it with Occupant the script doesn't work. CaptainAlien132 225 — 5y
0
Nevermind, GetPropertyChangedSignal works. CaptainAlien132 225 — 5y
Ad

Answer this question