I’ve got an animation that is running inside of a moving body (train), it’s a door that needs to open and close but it only works for the driver of the body 100% of the time, on the server and other clients the doors won’t close and sometimes don’t open at all. These scripts are quite messy so any cleanup would be appreciated
Open script
local AnimationID = 'rbxassetid://XXXXXXXX'
script.Parent.CloseDoorsL.Disabled = true
script.Parent.Doors.Left.DoorSet.Base.Open:Play()
script.Parent.Doors.Left.DoorSet1.Base.Open:Play()
wait(0.75)
local newAnimation = Instance.new( 'Animation' )
newAnimation.AnimationId = AnimationID
local newAnimation1 = Instance.new( 'Animation' )
newAnimation1.AnimationId = AnimationID
local track = script.Parent.Doors.Left.DoorSet.Humanoid:LoadAnimation( newAnimation )
local track1 = script.Parent.Doors.Left.DoorSet1.Humanoid:LoadAnimation( newAnimation1 )
track:Play()
track1:Play()
repeat wait() until track.TimePosition ~= 0 and track1.TimePosition ~= 0
track1.Looped = false
track.Looped = false
wait( track.Length - ( 0.1 + track.TimePosition ) )
track:AdjustSpeed(0)
track1:AdjustSpeed(0)
track:Destroy()
track1:Destroy()
newAnimation:Destroy()
newAnimation1:Destroy()
Close script:
script.Parent.OpenDoorsL.Disabled = true
script.Parent.Doors.Left.DoorSet.Base.Close:Play()
script.Parent.Doors.Left.DoorSet1.Base.Close:Play()
wait(3)
local newAnimation = Instance.new( 'Animation' )
newAnimation.AnimationId = 'rbxassetid://XXXXXX'
local track = script.Parent.Doors.Left.DoorSet.Humanoid:LoadAnimation( newAnimation )
local track1 = script.Parent.Doors.Left.DoorSet1.Humanoid:LoadAnimation( newAnimation )
track:Play( track.Length, 1, -1 )
track1:Play( track1.Length, 1, -1 )
repeat wait() until track.TimePosition ~= track.Length and track1.TimePosition ~= track1.Length
track.Looped = false
track1.Looped = false
track:Destroy()
track1:Destroy()
newAnimation:Destroy()
Is there any way to fix the differences in replication of the animation from client to client? Maybe implementing a part where is forces the doors to be in the open/closed position at the end of animation?