I have created some animations for a gun which includes an Equipped, Idle, and ADS animations, and wrote a script to play them when needed, the issue is when they play for the first time, near the end it sort of spazzes out for a frame or 2 until the next animation is played. the weird thing is that it only happens when the animations are played for the first time. after which they work perfectly.
Is there a reason why its doing that?
script:
local tool = script.Parent
local idleAnim = script.Idle
local equipAnim = script.Equip
local aimAnim = script.Aim
local ads = script.Parent.ADS
local tracks = {}
tool.Equipped:Connect(function()
local humanoid = tool.Parent.Humanoid
local animator = humanoid.Animator
--gets grip weld and replaces it with a Motor6D
local grip = tool.Parent.RightHand.RightGrip
local motor6D = Instance.new("Motor6D", grip.Parent)
motor6D.Name = "Gun"
motor6D.Part0 = grip.Part0
motor6D.Part1 = grip.Part1
grip:Destroy()
--loads tracks if not loaded already
if not tracks.Equip or tracks.Idle or tracks.Aim then
tracks.Equip = animator:LoadAnimation(equipAnim)
tracks.Idle = animator:LoadAnimation(idleAnim)
tracks.Aim = animator:LoadAnimation(aimAnim)
end
--plays equip animation
tracks.Equip:Play(0)
--plays looping idle animation once equip animation is finished
tracks.Equip.Stopped:Connect(function()
tracks.Equip:Stop()
tracks.Idle:Play(0)
end)
end)
ads.OnServerEvent:Connect(function(plr, value)
--plays ADS or normal idle animnation depending on user input
if value then
tracks.Idle:Stop()
tracks.Aim:Play(0)
else
tracks.Aim:Stop()
tracks.Idle:Play(0)
end
end)
tool.Unequipped:Connect(function()
tracks.Idle:Stop()
end)
Video of weird behavior: