Animation won't play?

I’ve got this aim down sights script, and I want to make it play this animation when ADSing to make it look like the player is holding the gun closer to the screen. This code is copied from a zombie attacking animation script combined with the base ADS script, but it doesn’t work. Help?

local Humanoid = script.Parent

local gun = script.Parent
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse setup
local mouse = game.Players.LocalPlayer:GetMouse()

local aimAnimation = Humanoid:LoadAnimation(script:WaitForChild("AimHold"))




local isEquipped = false


gun.Equipped:Connect(function()
	isEquipped = true
end)


gun.Unequipped:Connect(function()
	isEquipped = false
end)



mouse.Button2Down:Connect(function()
	if not isEquipped then
		return 
	end

	local camera = game.Workspace.CurrentCamera
	camera.FieldOfView = 50
	
	aimAnimation:Play()
	
	
	
	
end)



mouse.Button2Up:Connect(function()
	if not isEquipped then
		return
	end

	local camera = game.Workspace.CurrentCamera
	
	
	camera.FieldOfView = 70
	

	
	
	
end)

aim hold

Side note but Humanoid:LoadAnimation is deprecated, if you can use the Animator inside the Humanoid instead (I believe)

Did you set the AnimationPriority to Action?

So i just set it to action and it’ll work, or do I have to do something else too?

You can try it and see if it works or not

W a i t

Why do you have 2 variables that are equal to the script’s Parent?

its just a bunch of free model scripts i cobbled together.

also it didn’t seem to work. do i have to set the animation to loop?

You shouldn’t need to, you could try it I suppose if you want

Are you getting any errors from your Output at all?

nothing relating to the gun’s ADS script.

oh wait i forgot to turn off the duplicated ads script i would use if the animation thing didn’t work

The only potential error that I could see is the attempt to call a nil value, could you try this and see what gets outputted?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local gun = script.Parent
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse setup
local mouse = game.Players.LocalPlayer:GetMouse()
local aimAnimation = Humanoid:LoadAnimation(script:WaitForChild("AimHold"))
local isEquipped = false
print("Script loaded")

gun.Equipped:Connect(function()
	isEquipped = true
end)

gun.Unequipped:Connect(function()
	isEquipped = false
end)

mouse.Button2Down:Connect(function()
    print(isEquipped)
	if not isEquipped then
		return 
	end

	local camera = game.Workspace.CurrentCamera
	camera.FieldOfView = 50
	aimAnimation:Play()
    print("Animation Playing")
end)

mouse.Button2Up:Connect(function()
    print(isEquipped)
	if not isEquipped then
		return
	end

	local camera = game.Workspace.CurrentCamera
	camera.FieldOfView = 70
    print("Fixing camera")
end)

nope, nothing. and it still has that duplicating nil error

I think I may know where the issue lies, but I’m not sure

You have 2 variables that are defining the script’s Parent, and it could be because of that but I’m not exactly sure

I edited the code, could you try again? The Script should be a Parent of the Tool (Or Gun)

it works now, but how do i stop the animation when right click is let go of?

Ah just stop the animation inside your Button2Up Event using aimAnimation:Stop()

I believe that should be everything to fix it, but if you have any more issues then do feel free to reply back

1 Like