local gun = script.Parent
local aim = gun.aiming --boolvalue to toggle on and off

gun.Equipped:Connect(function()
	function onKeyPress(inputObject, gameProcessedEvent)
	    local aim = script.aim
	    if inputObject.KeyCode == Enum.KeyCode.Q then
	        aim.Value = not aim.Value
	        if aim.Value == true then
	        local toggle = script.Parent.Parent.Humanoid:LoadAnimation(script.Aim)
	        toggle:Play()
	    elseif aim.Value == false then
	        local toggle = script.Parent.Parent.Humanoid:LoadAnimation(script.Aim)
	       	toggle:Stop()
	   		end
		end
	end
end)

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

In my gun tool I have a script that if you press q it would play an animation. If you press q again the animation will stop. My error is "attempt to call a nil value."

3 comments

0

What line

0

It doesn't say a line in the error

0

Click the error in Output, it will send you to the source.