Animations not playing correctly

I am triggering a door open and close animation, and I want there to be a wait in-between an open animation and a close animation, but when the open animation finishes, the door goes straight back to closed, then when the close animation animation plays, it opens and closes. Am I doing something wrong with scripting or animating? How do I fix this?

Animation:Pause() can make it so u can pause the animation. Just use that half way through the animation and unpause it after how long you want the door to be open. Or you could just make the open and close animation seperate.

They are separate, but it’s still doing that.

just add a task.wait(how ever long u want it to wait) in between the two lines where the the animations play

That’s not the problem, here is the code:

local openAnimTrack = animator:LoadAnimation(openAnimation)
	openAnimTrack:Play()
	wait(0.3)
local closeAnimTrack = animator:LoadAnimation(closeAnimation)
	closeAnimTrack:Play()

It is returning to the original state of the object being animated after being animated, then it is going to the wait.

You are playing the second animation before the first animation finish try this instead:

local openAnimTrack = animator:LoadAnimation(openAnimation)
local closeAnimTrack = animator:LoadAnimation(closeAnimation)
	openAnimTrack:Play()
	openAnimTrack.Stopped:Wait()
	closeAnimTrack:Play()

I have a new script:

local function animateFridge(plr, fridge)
	local fridgeAnimator = script.Parent.FridgeCore.AnimationController.Animator
	local openAnimation = script.Parent.FridgeCore.Animations.DoorOpen
	local closeAnimation = script.Parent.FridgeCore.Animations.DoorClose

	local openAnimTrack = fridgeAnimator:LoadAnimation(openAnimation)
	
	local character = plr.Character
	if not character or not character.Parent then
		character = plr.CharacterAdded:Wait()
	end
	local humanoid = character:WaitForChild("Humanoid")
	local animator = humanoid:WaitForChild("Animator")
	local reachForDrink = Instance.new("Animation")
	reachForDrink.AnimationId = "rbxassetid://9203026680"
	local reachForDrinkTrack = animator:LoadAnimation(reachForDrink)
	
	local closeAnimTrack = fridgeAnimator:LoadAnimation(closeAnimation)
	
	openAnimTrack:Play()
	openAnimTrack.Stopped:Wait(0.6)
	reachForDrinkTrack:Play()
	reachForDrinkTrack.Stopped:Wait(2)
	closeAnimTrack:Play()
	closeAnimTrack.Stopped:Wait(0.1)
end

The problem I’m having is that the fridge will open and close, then the player will reach for the drink, then the fridge will open and close again. How do I fix this?

You shouldn’t put number inside this line from what I remember.
If you want to delay it use Task.wait(--your number here) after this line.

1 Like

It’s still doing the same thing. Should I just combine the open and close animation into one, and pause in the middle for the player animation?

Are you sure you want the door to have a custom animation? Is there something preventing you from wanting to utilize tween service?

Oh, I’ve never heard of it before. I just did some research on DevHub, but this will be the first time I’m using it, so how would I use it to animate a door opening and closing? What property would I use? How would I use it to turn an object 90 degrees?

Get your door model, make a new part, name it hinge, and then put it wherever you want your door to turn from:

image

Have EVERY single part unanchored EXCEPT for the hinge that I told you to add before. After that, weld all the parts to the hinge, you can either do it manually (I personally recommend WeldConstraints) or automatically (I still recommend WeldConstraints). You can do researcher on automatic welding scripts but I can provide that if you want. Once you added all the welds have all the parts of the door that you want to turn under a model and put the hinge in there as well.

local TweenService = game:GetService("TweenService") -- Gets the service tweenservice so you can use it
local hinge = script.Parent.Hinge

local info = TweenInfo.new( -- tells the door on how to animate
	2, -- how long you want the door to open/close (in seconds)
	Enum.EasingStyle.Sine, -- search up tweenservice easing styles for more information, sine makes it smooth and slows down the animation towards the end
	Enum.EasingDirection.Out, -- again, search it up for more information, determines where you want the easingstyle to take place
	0, -- how many times to repeat animation, for your case, set it to 0,
	false, -- reverse: boolean? will reverse the animation once it completed its animation, for your case, set it to false since this is the exact opposite you want
	0 -- delay time, you can change this but I'm assuming you want it to open with no delay
)

local open = TweenService:Create(hinge,info,{CFrame = hinge.CFrame*CFrame.Angles(0,math.rad(90),0)})
local close = TweenService:Create(hinge,info,{CFrame = hinge.CFrame})

--[[
HOW TO OPEN AND CLOSE DOORS:

when you want to open the door, use open:Play()
otherwise when you want to close the door, use close:Play()

]]

It’s just that simple!
If you come across a problem you can tell me or do further research on TweenService, there are plenty of great tutorials out there and I’ll even drop some of them below:

this video only goes over tweenservice and not how to use it for doors, although it’ll teach you how to use tweenservice for a variety of purposes farther than just doors

be careful when using this tutorial, do research on what CFrame.LookVector is before using his script.

1 Like

How would I modify the script to open 2 doors at the same time?

If you mean two separate doors, you would do the same thing but duplicate the variables “open” and “close” and modify the parameters for your second door.

Otherwise if you’re talking about two parts of the same door, then the second video link I sent in my last reply will answer that question