I currently have a tool, and they are animated with Motor6Ds. I have a viewmodel for the first person, and proper animations for third person.
The equip, hold and aiming animations all work correctly. However, firing while aiming will break the animations, causing the viewmodel to be stuck in the aim holding animation, and not backing out even when I release right click.
“Steelsight” stands for aiming and “hold” stands for holding animations.
UserInputService.InputBegan:Connect(function(input)
if script.Parent.Parent:FindFirstChildOfClass("Humanoid") then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
firing = true
if steelsight then
load = animator:LoadAnimation(anim_steelsight_fire)
else
load = animator:LoadAnimation(anim_fire)
end
load.Priority = Enum.AnimationPriority.Action
load:Play()
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
steelsight = true
load = animator:LoadAnimation(anim_steelsight)
load.Priority = Enum.AnimationPriority.Action
load:Play()
load = animator:LoadAnimation(anim_steelsight_hold)
load.Priority = Enum.AnimationPriority.Action
load:Play()
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if script.Parent.Parent:FindFirstChildOfClass("Humanoid") then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
firing = false
load:Stop()
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
steelsight = false
load:Stop()
end
end
end)
I’m thinking when you aim, you set load to the aim animation but when you shoot + aim you set the load to shoot animation meaning the aim animation never finishes playing. I suggest the animations in variables to fix this.
I think the spam loaded animations pile up inside the animator and this might cause issues… Maybe? What do you lose by storing them in variables? Its only like 4 animations
Yes, store the loaded animations in a variable. I personally prefer keeping them in a table.
If you were doing it because of too many variables then you can use a function. Here’s an example function I used:
Handler.LoadAnimation = function(Character:Model, AnimId:number) : AnimationTrack?
if not Character or not AnimId then return end
local Hum = Character:FindFirstChildOfClass("Humanoid")
if not Hum or Hum:GetState() == Enum.HumanoidStateType.Dead then return end
local Animator = Hum:FindFirstChildOfClass("Animator")
if not Animator then return end
local Anim = Instance.new("Animation")
Anim.AnimationId = `rbxassetid://{AnimId}`
local Track = Animator:LoadAnimation(Anim)
Anim:Destroy()
Anim = nil
return Track
end
After this I would do:
local RandomAnimation = Module.LoadAnimation(Character, ID)
RandomAnimation:Play()