Help me with the door animation of this train!

Hello, I’m trying to animate the doors of my train with an Animation i’ve created for them. It is supposed to look like this:

Sometimes, for other players, the only doors they can see with its current status of the animation are the ones in the middle wagon. However, if they touch the train’s hitbox, they can immediately see the actual position of all the train’s doors.

This is a part of the code that I used for the opening animation of the doors: (Script)

if train.MachinistSeat.Occupant then
			if RightDoorsOpen.Value == false and script.Parent.puertasDer.ImageTransparency == 0.5 then				
				for _, puerta in ipairs(train.PuertasDer:GetChildren()) do
					local animationController = puerta:FindFirstChild("AnimationController")
					if animationController then

						local animator = animationController.Animator
						local animTrack = animator:LoadAnimation(script.Parent.Apertura)

						spawn(function()
							openDoorsSound()
							animTrack:Play()
							wait(2.5)
							animTrack:AdjustSpeed(0)
						end)
					end
				end	
				script.Parent.puertasDer.ImageTransparency = 0
				train.Config.em_brake.Value = true
				RightDoorsOpen.Value = true

and this part for closing them:

for _, puerta in ipairs(train.PuertasDer:GetChildren()) do
					local animationController = puerta:FindFirstChild("AnimationController")
					if animationController then
						local animator = animationController.Animator
						local animTrack = animator:LoadAnimation(script.Parent.Apertura)
						spawn(function()
							closeDoorsSound()
							wait(3.5)
							animTrack:AdjustSpeed(-1)
							wait(2)
						end)	

					end
				end

				script.Parent.closeDoors.ImageTransparency = 0.5
				script.Parent.puertasDer.ImageTransparency = 0.5
				RightDoorsOpen.Value = false

All variables were assigned correctly. I’ve already tried using RemoteEvents but the issue persisted for all clients except for the one sat on the MachinistSeat of the train. Is it something related to Network Ownership? I’m new into scripting animations and have no idea about what’s going on

5 Likes

Hey did you find a fix for this, Im getting the same issue

Well… the only solution i found for this was to reanimate the doors using TweenSequence plugin, it’s a bit buggy but it worked for me, 'cause you can work with CFrame properties to animate them

Edit: The problem was that I was instancing animTrack every time the function was about to run, you have to localize it once globally in your code. For instance:

local puertas = {}

local abiertas = script.Parent.abiertas
local animTrack -- The global instance

puertas.abrirPuertas = function ()

	local animationController = script.Parent.AnimationController
	local animator = animationController.Animator

	animTrack = animTrack or animator:LoadAnimation(script.Parent.Apertura)

	-- and the rest of the code --

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.