Animation 1 Frame Delay?

I’m currently working on a custom inventory system for a game of mine and a friend that locally attaches the item models to the player’s ViewModel using a Motor6D. The problem is, every time I equip another item and play the idle and equip animations, there is a 1 frame delay when they’re played with fadeTime set to 0.
And yes, it’s visible even when your framerate is at 60 FPS.

I’m very sure it’s something inside Roblox’s code because my theory is that there’s a loop that manages the fade time that uses RunService.RenderStepped:Wait()

https://gyazo.com/d4bae57592133ca4bbf150e9417ef05e

If it’s really just Roblox’s own code, then this is how they can change it:

Script
while FadingOrSomethingIdk do
	if FadeTime >= TargetFadeTime then
		break
	end
	
	ChangeMotorCFrameSomehow()
	
	RunService.PreRender:Wait()
end

Is there a workaround to this?
Thanks for reading :slight_smile:

1 Like

This text will be blurred so I can reply

Can you display your code??

I’ll leave the necessary things that tie to the animation playing and stopping.

Item Script
EquippedItem:GetValChanged(function(ItemValue)
	EffectsModule:ParentItemModels(ItemValue,PreviousItemValue,ItemsFolder)

	local PreviousItemModuleTable = PreviousItemValue and ItemModuleTables[PreviousItemValue] or HandsItemModuleTable
	if PreviousItemModuleTable then
		for _,Animation in pairs(PreviousItemModuleTable.Animations.All) do
			Animation:Stop(0)
		end
	end
	PreviousItemValue = ItemValue

	if ItemValue then
		local MotorsFolder = ItemValue:FindFirstChild("Motors")
		if MotorsFolder then
			for _,Motor in pairs(MotorsFolder:GetChildren()) do
				local AttachPartName = Motor.Part0 and Motor.Part0.Name
				if AttachPartName then
					local AttachPart = ViewModel:FindFirstChild(AttachPartName)
					if AttachPart then
						Motor.Part0 = AttachPart
					end
				end
			end
		end
	end


	local ItemModule = ItemValue and ItemValue.ItemModule.Value
	if not ItemValue then
		ItemModule = ReplicatedStorage.ItemModules.Hands
	end

	if ItemModule then
		local IdleAnimationTable = Animations.Main.Idle
		if IdleAnimationTable then
			PlayAnimationTable(IdleAnimationTable)
		end
	end
end)
Item Model Parenting
function EffectsModule:ParentItemModels(ItemValue,PreviousItemValue,ItemsFolder)
	if PreviousItemValue and PreviousItemValue:IsDescendantOf(ItemsFolder)  then
		local PreviousItemModel = PreviousItemValue.Value
		if PreviousItemModel then
			PreviousItemModel.Parent = HiddenItemModelsFolder
		end
	end
	
	if ItemValue then
		local ItemModel = ItemValue.Value
		if ItemModel then
			ItemModel.Parent = ItemValue
		end
	end
end

try rendering the models. I found an example devforum you would have to make it yourself so it can work with your inventory system.

That’s not really the problem, the problem is that animations have a 1 frame delay before visibly changing the character and viewmodel.

1 Like