Animation not playing

Hi everyone,

I tried creating a simple door animation for a train, but the animation will not play. I set it up as a LocalScript inside a button that communicates to a Script via RemoteEvent; event fires fine, debug prints are working. However, the animation does not play, despite the fact that the script prints that it was able to start playing it.

LocalScript:

local btn = script.Parent
local plr = game.Players.LocalPlayer

local event = game:GetService("ReplicatedStorage").doors

btn.MouseButton1Click:Connect(function()
	local train = plr.Character.Humanoid.SeatPart.Parent
	print(train.Name)
	event:FireServer(train)
end)

Script:

local event = game:GetService("ReplicatedStorage").doors
local doorsleft = script.Left
local doorsright = script.Right

event.OnServerEvent:Connect(function(p, train) -- the disabled code is for testing
	--for i, car in pairs(train:GetChildren()) do
	--	if car.Name == "Carriage1" then
			local model = train.Carriage1.model
			local hum = model.Humanoid
			local animator = hum:WaitForChild("Animator")
			
			local leftTrack = animator:LoadAnimation(doorsleft)
			
			leftTrack:Play()
			
			print("track playing")
	--	end
	--end
end)

This is a really simple problem and the answer is probably that I’m being stupid, but any help would be great. Thanks!

1 Like

In general, animations should be used for players (characters) only, not for non-player entities like doors. Use TweenService instead.

Why would that be? No, you can use Animations for non-character entities. TweenService is just used for animations like a door swinging open for simplicity. But it’s perfectly fine to animate, for example, a garage door opening with an animation.

That’s exactly what TweenService is used for, animating stuff like opening a door, etc…

And for whatever’s not covered there, you have tons of constraints and angularvelocities and whatnot that I don’t even fully understand that do some magic to move your part from place A to place B while still following the laws of physics.

On the other hand, the Animations system is designed for characters (hence why it uses a Humanoid (meant for characters)). It isn’t the intended purpose of the system, just like how making a model, shoving a humanoid and a part named “Head” inside of it and naming it isn’t the intended way of using a Humanoid, and adding text over a part (use a BillboardGUI instead).

That’s an assumption that’s not true. You can plug animations into any rig with a Motor6D. Where there is there a character? A Humanoid is not required - use an AnimationController.

If you want to animate complex systems - be it a door, a character, a monster or a soda can, you’re free to plug in animations. They’re not restricted to characters.

TweenService is for smooth transitions through code for individual objects. Don’t use it for complex systems where parts move one after the other, at the same time, depending on one another… It’ll get messy. Use an Animation.