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()
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