Tool hold animation not playing correctly

Title.

Basically when I am in the animation editor the hold/idle animation for my weapon plays fine, but when I play the animation on my character it doesn’t show the animation properly.



Animation Editor


In Game

I’ve been banging my head for an hour trying to fix this lol. I’ve looked over the forum and no one else seems to have this issue.

Script if needed:

local anims = tool.Anims do
	
	function playAnimations(chr, anim, priority)
		
		local hum = chr:FindFirstChildOfClass("Humanoid")
		assert(hum, "No Humanoid found")
		
		if not hum:FindFirstChildOfClass("Animator") then

			local animator = Instance.new("Animator")
			animator.Name = "Animator"
			animator.Parent = hum

		end
		
		local animator = hum:FindFirstChild("Animator")
		
		local animTrack = animator:LoadAnimation(anim)
		animTrack.Priority = priority
		
		return animTrack
	end
	
	holdAnim = anims.HoldAnim
	
end
local Debris = game:GetService("Debris")
local Players = game:GetService("Players")

local tool = script.Parent
local handle = tool.Handle
local mouseLoc = tool.MouseLoc
local reloadEvent = tool.RE.Reload
local firingEvent = tool.RE.Firing

local shootSound = script.Shoot
local reloadSound = script.Reload
local bulletScript = script.Bullet

local GRAV = workspace.Gravity

----	CUSTOMIZABLE PROPERTIES		----

local BULLET_SPEED = 280
local FIRE_RATE = 0.1
local RELOAD_TIME = reloadSound.TimeLength 	--	Can be changed to a number value
local MAG_SIZE = 30
local CHAMBERED_MAG_SIZE = MAG_SIZE + 1

----	CUSTOMIZABLE PROPERTIES		----

local plr = tool.Parent.Parent
local chr = plr.Character or plr.CharacterAdded:Wait()
local hum = chr:WaitForChild("Humanoid")

game:GetService("RunService").Stepped:Wait()

local anims = tool.Anims do
	
	function playAnimations(chr, anim, priority)
		
		local hum = chr:FindFirstChildOfClass("Humanoid")
		assert(hum, "No Humanoid found")
		
		if not hum:FindFirstChildOfClass("Animator") then

			local animator = Instance.new("Animator")
			animator.Name = "Animator"
			animator.Parent = hum

		end
		
		local animator = hum:FindFirstChild("Animator")
		
		local animTrack = animator:LoadAnimation(anim)
		animTrack.Priority = priority
		
		return animTrack
	end
	
	holdAnim = anims.HoldAnim
	
end

local bullet = Instance.new("Part") do

	bullet.Name = "Bullet"
	bullet.Shape = Enum.PartType.Ball
	bullet.Size = Vector3.new(0.25, 0.25, 0.25)
	bullet.CanCollide = false
	bullet.Color = Color3.fromRGB(190, 190, 190)

	local att = Instance.new("Attachment")
	att.Parent = bullet

	local vf = Instance.new("VectorForce")
	vf.Name = "ANTIGRAV"
	vf.Attachment0 = att
	vf.RelativeTo = Enum.ActuatorRelativeTo.World
	vf.Force = Vector3.new(0, bullet:GetMass() * GRAV, 0)
	vf.Parent = bullet

	local creatorTag = Instance.new("ObjectValue")
	creatorTag.Value = plr
	creatorTag.Name = "CREATOR" -- change to 'creator' for website stats
	creatorTag.Parent = bullet

	local bulletScriptClone = bulletScript:Clone()
	bulletScriptClone.Enabled = true
	bulletScriptClone.Parent = bullet

end

local bulletCount = CHAMBERED_MAG_SIZE
local reloading = false

local function ammoCountToClient(chambered)
	
	firingEvent:FireClient(plr, bulletCount, MAG_SIZE, chambered)
	
end

ammoCountToClient(true)

local function checkAmmoCount()

	if bulletCount <= 0 and not reloading then
		reloading = true
		tool.Enabled = false

		local reloadClone = reloadSound:Clone()
		reloadClone.Parent = handle
		reloadClone:Play()
		Debris:AddItem(reloadClone, RELOAD_TIME)

		task.wait(RELOAD_TIME)
		bulletCount = MAG_SIZE
		
		tool.Enabled = true
		reloading = false
		
		ammoCountToClient(false)
	end
end

tool.Equipped:Connect(function()
	
	plr = Players:GetPlayerFromCharacter(tool.Parent)
	
	holdTrack = playAnimations(chr, holdAnim, Enum.AnimationPriority.Idle)
	holdTrack:Play()

end)

tool.Unequipped:Connect(function()
	
	if holdTrack then
		holdTrack:Stop()
	end
	
end)

tool.Activated:Connect(function()

	if tool.Enabled and chr and chr.Humanoid.Health > 0 then
		
		checkAmmoCount()
		
	end
end)

firingEvent.OnServerEvent:Connect(function(plr, firing)
	tool:SetAttribute("Firing", firing)
	
	checkAmmoCount()

	while tool:GetAttribute("Firing", true) and bulletCount > 0 do

		local shootClone = shootSound:Clone()

		bulletCount -= 1
		
		ammoCountToClient(false)

		local mousePos = mouseLoc:InvokeClient(plr)

		local bulletClone = bullet:Clone()
		Debris:AddItem(bulletClone, 10)

		shootClone.Parent = handle
		shootClone:Play()
		Debris:AddItem(shootClone, shootClone.TimeLength)

		local spawnPos = (tool.Handle.CFrame * CFrame.new(1, 0, 0)).Position
		bulletClone.CFrame = CFrame.new(spawnPos, mousePos)
		bulletClone.AssemblyLinearVelocity = (bulletClone.CFrame.LookVector * BULLET_SPEED)
		bulletClone.Parent = workspace
		bulletClone:SetNetworkOwner(nil)

		task.wait(FIRE_RATE)

	end
end)

reloadEvent.OnServerEvent:Connect(function()

	if bulletCount == CHAMBERED_MAG_SIZE then return end
	if reloading == true then return end
	
	reloading = true

	local reloadClone = reloadSound:Clone()
	reloadClone.Parent = handle
	reloadClone:Play()
	Debris:AddItem(reloadClone, RELOAD_TIME)

	if bulletCount < CHAMBERED_MAG_SIZE and bulletCount > 0 then
		tool.Enabled = false

		task.wait(RELOAD_TIME)
		bulletCount = CHAMBERED_MAG_SIZE
		reloading = false
		
		tool.Enabled = true
		
		ammoCountToClient(true)

	elseif bulletCount <= 0 then
		tool.Enabled = false
		
		task.wait(RELOAD_TIME)
		bulletCount = MAG_SIZE
		reloading = false
		
		tool.Enabled = true
		
		ammoCountToClient(false)

	end
end)

Set the animation priority to the highest one.

2 Likes

btw… restart the roblox studio about plugins of against up

You’re a genius. Thank you!
It’s always something super easy that I miss haha

1 Like

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