Setting toolnone AnimationId

So I want to set the toolnone AnimationId when players equip a tool.

My approach is to have a local script inside of the tool that sets the animationId when it receives an event call from the tools server script.

Server Script

local Events = Tool.Events
local ChangeAnimation = Events:WaitForChild("ChangeAnimation")

function equip()
	Character = Tool.Parent
	Player = players:GetPlayerFromCharacter(Character)

	ChangeAnimation:FireClient(Player,"toolnone","rbxassetid://animationid")
end

Local Script

local Player = game.Players.LocalPlayer

local function SetAnimation(animationName, ids, reset)
	local character = Player.Character
	if not character then
		return
	end
	local animate = character:WaitForChild("Animate")
	if not animate then
		return
	end
	
	local tracks = animate:FindFirstChild(animationName)
	
	if tracks then
		for _, child in ipairs(tracks:GetChildren()) do
			if child:IsA("Animation") then
				child.AnimationId = id
			end
		end
	end
end


ChangeAnimationEvent:Connect(SetAnimation)

The problem with this approach is Roblox’s default Animate script calls the stepAnimate function on loop and checks the Character for a tool to determine if a tool has been equipped. the playToolAnimation function is then called which will load the animation for toolnone but as you can see in the code below it only loads the animation if the anim is not equal to the current toolAnimInstance.

Part of Roblox’s Animate Script

function playToolAnimation(animName, transitionTime, humanoid, priority)	 		
	local idx = rollAnimation(animName)
	local anim = animTable[animName][idx].anim
	if (toolAnimInstance ~= anim) then --This IF statement is what stops the new AnimationId from being used
			if (toolAnimTrack ~= nil) then
				toolAnimTrack:Stop()
				toolAnimTrack:Destroy()
				transitionTime = 0
			end
		
			-- load it to the humanoid; get AnimationTrack
			toolAnimTrack = humanoid:LoadAnimation(anim)
			if priority then
				toolAnimTrack.Priority = priority
			end
			 
			-- play the animation
			toolAnimTrack:Play(transitionTime)
			toolAnimName = animName
			toolAnimInstance = anim
		
		
			currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
		end
end

If my local script is executed first then my toolnone animation is used, but if the Animate script executes first then the default toolnone animation is used.

Things I’ve considered
I’ve tried to make changes to the Animate script so when it receives an event call it will reset toolAnimInstance to nil and execute the block of code for loading the animation, but this doesn’t seem to work.

I could probably just load a Action animation on loop when the tool is equipped but I figure the animation tracks inside of the Animate script are there for a reason and should be usable. Also this would interfere with other action scripts such as the attack animation.

Update
Tried using Action animations for toolidle but it stopped the attack animation from working.

1 Like