Animations Not Loading Correctly Again

So, I have been recent, as you might know, if you saw my past posts, been trying to make an OTS gun system, the only problem is that animations ain’t working. But passing to the important part, I have been trying to make the animations load, and eventually even managed to make them work but only idle animation. Now I tried to remake the code as a whole and it’s looking really bad ingame. Gives a ton of errors out of nowhere.
In case you need it, there you are the script.
–[[LOCALS]]–

local Weapon = script.Parent -- Variable for the Tool

local player = game.Players.LocalPlayer -- Gets the Player

repeat wait(1) until player.Character

local char = player.Character -- Gets the Player's character

local mouse = player:GetMouse()

local isEnabled = false

local hum = char:WaitForChild("Humanoid")

local Animator = hum:WaitForChild("Animator")

local HoldAnim = Animator:LoadAnimation(script.Idle_Anim)

local AimAnim = Animator:LoadAnimation(script.Aim_Anim)

--[[FUNCTIONS]]--

Weapon.Equipped:Connect(function() -- To start the animation whenever the Tool Is Equipped
	
	warn("equip")
	
	script.LidUp:Play()
	
	isEnabled = true
	
	if isEnabled == true and not mouse.Button2Down then
		
		mouse.Transparency = 1

		print("Hold")

	end
	
end) -- End of the function

Weapon.Unequipped:Connect(function()
	
	warn("unequip")
	
	script.LidDown:Play()
	
	HoldAnim:Stop()
	
	AimAnim:Stop()
	
	wait(0.025)
	
	isEnabled = false
	
end)

if mouse.Button2Up and not AimAnim then
	
	wait(0.01)
	
	AimAnim:Stop()
	
	wait(0.01)
	
	HoldAnim:Play()
	
end

if mouse.Button2Down and not HoldAnim then
	
	wait(0.01)
	
	HoldAnim:Stop()
	
	wait(0.01)
	
	AimAnim:Play()
	
end
1 Like

Use user input service(uis) > and then check using user input type.

UserInputService (roblox.com)
UserInputType (roblox.com)

You cant do things like if mouse.Button2Up > You need something to trigger the function in this case uis > you could also use cas > or you can do Tool.Activated which will trigger when the tool is clicked.

1 Like

This isn’t inside any kind of a loop or a function so it checks the if statements when the script runs and it never gets checked again.

Thanks, I think that will do, I apologize if I haven’t been good in writing my problem, in 3 years that’s my first time on one of my roblox accounts writing in DevForum.

Yeah, I realize that only now.

Tried to make that, and those works!
But now the tool plays animations when it’s unequipped.

while Weapon.Equipped do
	
	wait(0.1)
		
	HoldAnim:Play()
	
	if isEnabled == true then
		
		mouse.Button2Down:Connect(function()
			
			script.AimUp:Play()
			
			HoldAnim:Stop()

			AimAnim:Play()

			mouse.Button2Up:Connect(function()
				
				script.AimDown:Play()
				
				HoldAnim:Play()

				AimAnim:Stop()

			end)

		end)
				
	end
	
end

dont use a loop. you just need to add a check in between the mouse input >
mouse.Button2Up:Connect(function()
after this line can check to see if the tool is equipped.
if Weapon.Equipped ~= true then return end < adding that should fix.