I’m making my first weapon/tool so things aren’t going too smooth. Basically I want the gun to play the Idle Animation the second you equip it (obviously) and upon pressing F, if you have not done so already it will play a load animation then continue afterwards to an aiming animation. It’s sort of working half and half, the Idle Animation will play upon equipping the gun but once you press F it does run the line of code that tells it to play the Loading animation but it doesn’t show on the character. Oh and once you un-equip the weapon your still stuck in the aiming animation.
My code:
local InputService = game:GetService("UserInputService")
local Tool = script.Parent.Parent
local CoolDown = false
local Equipped = false
local Aiming = false
local Loaded = false
local Plr = game.Players.LocalPlayer
Tool.Equipped:Connect(function()
Equipped = true
-- Animations
local Idle = Tool.Assets.Animations.IdleAnimation
IdleAnim = Plr.Character.Humanoid:WaitForChild("Animator", 3):LoadAnimation(Idle)
local Aim = Tool.Assets.Animations.AimAnimation
AimAnim = Plr.Character.Humanoid:WaitForChild("Animator", 3):LoadAnimation(Aim)
local Load = Tool.Assets.Animations.AimAnimation
LoadAnim = Plr.Character.Humanoid:WaitForChild("Animator", 3):LoadAnimation(Load)
if Equipped then
IdleAnim:Play()
end
InputService.InputBegan:Connect(function(Input, Received)
if Input.UserInputType == Enum.UserInputType.MouseButton1 and not CoolDown and Equipped then
CoolDown = true
print("clicked")
CoolDown = false
elseif Input.UserInputType == Enum.UserInputType.Keyboard then
if Input.KeyCode == Enum.KeyCode.F then
if not Loaded then
print("loaded")
LoadAnim:Play()
LoadAnim.Stopped:Wait()
Loaded = true
end
if Loaded then
if Aiming == false then
Aiming = true
AimAnim:Play()
elseif Aiming == true then
Aiming = false
AimAnim:Stop()
end
end
end
end
end)
end)
Tool.Unequipped:Connect(function()
IdleAnim:Stop()
AimAnim:Stop()
LoadAnim:Stop()
Equipped = false
end)
EDIT: Fixed the aiming animation not stopping but I still am unable to figure why the loading animation won’t play.