Is it possible to script a tool with 2 different idles?

I’m a bit experienced with making animated tools so I was wondering if this was possible to script. Basically, I have a Recorder tool and I’d like for it to have two different idle animations depending on the mouse being clicked. I’m terrible at explaining so I made a doodle of what I’m talking about. I did try to look this up but I couldn’t find anything about it.

What I’m trying to explain:

My usual animation scripts for tools:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Modules = ReplicatedStorage:WaitForChild("Modules")
local Cooldown = require(Modules:WaitForChild("Cooldown"))
local PlayerScripts = Players.LocalPlayer:WaitForChild("PlayerScripts")
local Functions = PlayerScripts:WaitForChild("Functions")
local CooldownF = Functions:WaitForChild("Cooldown")

local Tool = script.Parent
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local FakeMedkit = Tool:WaitForChild("FakeMedkit")
local BodyAttach = FakeMedkit:WaitForChild("BodyAttach")


if not Character:IsDescendantOf(workspace) then
	while not Character:IsDescendantOf(workspace) and Character == Player.Character do task.wait() end
	if Player.Character ~= Character then return end
end

local IdleAnimation = Instance.new("Animation")
IdleAnimation.AnimationId = "rbxassetid://10598905500"
local I = Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(IdleAnimation)

local UseAnimation = Instance.new("Animation")
UseAnimation.AnimationId = "rbxassetid://10598908994"
local A = Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(UseAnimation)


Tool.Activated:Connect(function()
	if Player:GetAttribute("Grabbing") or Cooldown:IsOnCooldown(Player) or A.IsPlaying then return end

	A:Play()

	CooldownF:Invoke(2)
end)

Tool.Equipped:Connect(function()
	I:Play()
end)

Tool.Unequipped:Connect(function()
	A:Stop()
	I:Stop()
end)

Any n all help is appreciated.

2 Likes

Does the output give you any errors?

I don’t have anything on-hand for reference, but I know that the core Animator script used for Player characters uses random selection to achieve this. I believe the default animator package uses three possible idle animations, and one of them is selected to play whenever the character enters the idle state.

If you want it to be a bit more complex you could add weights to each animation to make one more likely to be selected than the others.

Alternatively, a simpler solution without randomness would be to just use a “switch” variable that is toggled every time an idle animation is selected. (Initially idle1 would be chosen, then idle2, then idle1, … etc.)

Edit:
Based on the wording of the initial post, if you’re just looking for these idle animations to play at specific times, then you could just store both animations in variables and play the appropriate one based on the player’s action.

if <player doing action A> then:
   <play animation one>

else:
   <play animation two>
1 Like

First of all, cool doodle you got there, i like it.
Now to the problem at hand. You could use a debounce

--assuming the tool is equipped
--play your idle 1 animation here

local Clicked = false

Tool.Activated:Connect(function()
   Clicked = not Clicked

   if Clicked then
      --play open animation
      --2 methods you can use here for idle 2
      --1: Stop Idle1 with AnimatrionTrack:Stop() and play Idle 2
      --2: Play Idle2 at a higher animation priority so you dont need to call :Stop() on Idle 1
   else
      --play close animation
      --stop playing idle2 animation and replay idle 1
   end
end)
1 Like

Thank y’all for replying! I’ll show how it went a bit later once I’m done eating breakfast.

Have you ever inspected the default ‘Animate’ script? It uses probabilities (weights) to roll between animations of a single type (state).

1 Like

Alright, that worked! Here’s a video of the tool in action. The animations are a bit wonky in some parts but I can always fix it later lol.