Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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 comment

1

you could use the GetPropertyChangedSignal method instead of a loop.

1 answer

✓ Accepted answer

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.

4 comments

0

It didn't work but I gave it a few edits, thanks for the help!

0

np

0

Also I was wondering how I would used the .Changed, whenever I try to use it with Occupant the script doesn't work.

0

Nevermind, GetPropertyChangedSignal works.

This discussion is preserved as it was. New answers, comments, and votes are closed.