Making a third person shooting game and I ran into some trouble with my animations and playing them at the correct times. More specifically, the animations won’t play at all, including the idle animation and firing animation. This probably isn’t the best code (hence why it’s not working) since i’m new at scripting with Lua but if anybody could give me some support I would appreciate it
local UserInputService = game:GetService(“UserInputService”)
local tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild(“Humanoid”)
local AnimationIdle = Instance.new (“Animation”)
AnimationIdle.AnimationId = “rbxassetid://6324827560” – Idle animation ID
local IdleTrack = Humanoid:LoadAnimation(AnimationIdle)
local AnimationFiring = Instance.new(“Animation”)
AnimationFiring.AnimationId = “rbxassetid://6324711571” – Firing animation ID
local FiringTrack = Humanoid:LoadAnimation(AnimationFiring)
tool.Equipped:Connect(function()
IdleTrack:Play() – Plays the idle animation on tool equip
end)
tool.Unequipped:Connect(function()
if IdleTrack then
IdleTrack:Stop() – Ends the idle animation on unequip
end
end)
UserInputService.InputBegan:Connect(function(InputObject)
if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
if IdleTrack then
IdleTrack:Stop() – Ends the idle animation on firing animation
end
FiringTrack:Play() – Plays the firing animation
end
end)