Aim animation won't stop even when using Stop()

I’ve got an aiming animation local script. I for some reason decided to separate the main gun local script and the aiming local script. To make the aim animation stop when the main gun script demands it, I used RenderStepped values. It seems to work, but for some reason, if the current aim animation is playing and the main gun script starts a reload, the aim animation will just not be stopped. Help?

Main gun relevent code:

local function Reload()
	if not Reloading and IsSprinting.Value == false and IsSprintAnim.Value == false then
		Reloading = true
		-- Don't reload if you are already full or have no extra ammo
		if AmmoInClip ~= ClipSize and script.Parent.Values.MaxAmmo.Value > 0 then
			if HipRecoilTrack and AimRecoilTrack then -- leave empty until better fix can be implemented for stop reloading while shooting
				
			end
			
			if IsShooting == true then -- hopefully temporary fix for stop reloading while shooting
				Reloading = false
			end
		
			
			if IsShooting == false then -- hopefully temporary fix for stop reloading while shooting
				
			Player.IsReloading.Value = true
			task.wait()
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) -- disable inventory	
				
			Camera.FieldOfView = 70
				
			script.Parent.MeleeKeybind.Disabled = true	
				
			script.Parent.MeleeKeybind.Disabled = true
		
			game.Players.LocalPlayer.PlayerGui.WeaponHud.AmmoHud.AmmoStatus.TextTransparency = 1	
				
			script.Parent.ADSScript.Disabled = true	
			
			script.Parent.AimModel.AimWood.Transparency = 1
			script.Parent.AimModel.AimMetal.Transparency = 1
			script.Parent.AimModel.AimBolt.Transparency = 1

			script.Parent.WorldModel.WorldWood.Transparency = 0
			script.Parent.WorldModel.WorldMetal.Transparency = 0
			script.Parent.WorldModel.CloseBolt.Transparency = 0
				
			if AmmoInClip < 1 then  -- Empty Reload
			print("Empty Reload Commenced")
			EmptyReloadTrack:Play() --Reload Lines
			EmptyReloadEvent:FireServer(Player)
			wait(EmptyReloadTime)	
			end	
			
			if AmmoInClip >= 1 then  -- Partial Reload
			print("Partial Reload Commenced")	
			PartialReloadTrack:Play() --Reload Lines
			PartialReloadEvent:FireServer(Player)
			wait(PartialReloadTime)	
			end	
				
			Player.IsReloading.Value = false	
				
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true) -- enable inventory		
				
			script.Parent.MeleeKeybind.Disabled = false
		
			script.Parent.ADSScript.Disabled = false		
	
			-- Only use as much ammo as you have
			local ammoToUse = math.min(ClipSize - AmmoInClip, SpareAmmo)
			AmmoInClip = AmmoInClip + ammoToUse
			script.Parent.Values.MaxAmmo.Value = script.Parent.Values.MaxAmmo.Value - ammoToUse
			UpdateAmmo(AmmoInClip)
			end
		end
		Reloading = false
	end
end

Aim script:

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:WaitForChild("Humanoid")

local Gun = script.Parent

local IsAnimSprinting = script.Parent.Values:WaitForChild("IsSprintAnim")
local IsSprinting = Player:WaitForChild("IsSprinting")

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

local AimAnimation = Humanoid:LoadAnimation(script.Parent:WaitForChild("AimHoldAnimation"))
local MoveToAimAnimation = Humanoid:LoadAnimation(script.Parent:WaitForChild("MoveToAimAnimation"))
local MoveToUnAimAnimation = Humanoid:LoadAnimation(script.Parent:WaitForChild("MoveToUnAimAnimation"))

local RunService = game:GetService("RunService")

local isEquipped = false
print("Script loaded")

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

Gun.Unequipped:Connect(function()
	isEquipped = false
	AimAnimation:Stop()
end)

local IsAiming = Player:WaitForChild("IsAiming") -- player status values setup
local IsReloading = Player:WaitForChild("IsReloading")
local IsAimFiring = Player:WaitForChild("IsAimFiring")
local IsHipFiring = Player:WaitForChild("IsHipFiring")

Mouse.Button2Down:Connect(function()
	AimAnimation:Stop()
	
	print(isEquipped)
	if not isEquipped then
		return 
	end
	
	if IsAnimSprinting.Value == true or IsSprinting.Value == true then
		return
	end
	
	MoveToAimAnimation:Play()
	
	wait(0.1)
	
	AimAnimation:Play()
	
	script.Parent.Handle.AimSound:Play()
	
	IsAiming.Value = true
	
	script.Parent.AimModel.AimWood.Transparency = 0
	script.Parent.AimModel.AimMetal.Transparency = 0
	script.Parent.AimModel.AimBolt.Transparency = 0
	
	script.Parent.WorldModel.WorldWood.Transparency = 1
	script.Parent.WorldModel.WorldMetal.Transparency = 1
	script.Parent.WorldModel.CloseBolt.Transparency = 1
	
	print("Animation Playing")

end)

Mouse.Button2Up:Connect(function()
	print(isEquipped)
	if not isEquipped then
		return
	end
	
	if IsAnimSprinting.Value == true and IsSprinting.Value == true then
		return
	end
	
	MoveToUnAimAnimation:Play()
	
	wait(0.1)
	
	AimAnimation:Stop()
	
	IsAiming.Value = false
	
	script.Parent.AimModel.AimWood.Transparency = 1
	script.Parent.AimModel.AimMetal.Transparency = 1
	script.Parent.AimModel.AimBolt.Transparency = 1

	script.Parent.WorldModel.WorldWood.Transparency = 0
	script.Parent.WorldModel.WorldMetal.Transparency = 0
	script.Parent.WorldModel.CloseBolt.Transparency = 0
	AimAnimation:Stop()
end)



RunService.RenderStepped:Connect(function() -- reloading animation disable
if IsReloading.Value == true then
	task.wait()
	AimAnimation:Stop()
	MoveToAimAnimation:Stop()
	IsAiming.Value = false	
	script.Parent.AimModel.AimWood.Transparency = 1
	script.Parent.AimModel.AimMetal.Transparency = 1
	script.Parent.AimModel.AimBolt.Transparency = 1
end		
end)

RunService.RenderStepped:Connect(function() -- hipfiring animation disable
	if IsHipFiring.Value == true then
		AimAnimation:Stop()
		MoveToAimAnimation:Stop()
		IsAiming.Value = false	
		script.Parent.AimModel.AimWood.Transparency = 1
		script.Parent.AimModel.AimMetal.Transparency = 1
		script.Parent.AimModel.AimBolt.Transparency = 1
	end		
end)

RunService.RenderStepped:Connect(function() -- aimfiring animation disable
	if IsAimFiring.Value == true then
		AimAnimation:Stop()
		IsAiming.Value = false
		script.Parent.AimModel.AimWood.Transparency = 1
		script.Parent.AimModel.AimMetal.Transparency = 1
		script.Parent.AimModel.AimBolt.Transparency = 1
	end		
end)

RunService.RenderStepped:Connect(function() -- unequip animation disable
	if script.Parent.Values.UnEquipping.Value == true then
		AimAnimation:Stop()
		IsAiming.Value = false
		script.Parent.AimModel.AimWood.Transparency = 1
		script.Parent.AimModel.AimMetal.Transparency = 1
		script.Parent.AimModel.AimBolt.Transparency = 1
		
		script.Parent.WorldModel.CloseBolt.Transparency = 0
		script.Parent.WorldModel.WorldWood.Transparency = 0
		script.Parent.WorldModel.WorldMetal.Transparency = 0
	end		
end)
1 Like

nvm all i had to do was check if the player was aiming again and if they were, i had to stop them from aiming again which was cloning the first animation

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.