How to make animation reusable

So i want to make an animation, but its not for just one tool, I want to make it only for a spesific type of tool.

Its kinda similar how Pilgrammed used their animation ( like if heavy weapon the player will carries it with their back. And if its light weapon the player will carries it with one single hand )

i’ve tried searching in the internet but cant find any solution, please help

(I just need a enlightenment how to do this, and not the entire scripts)

I’d assume you’re a beginner scripter. Put it simply, you can just copy the same animation ID to every specific tool type you want. I will admit though, this is rather tedious, especially if you have multiple tools reusing the same animation again.

(This is a little disclaimer since I’ll go ramble about something you might struggle with.)

If you are feeling confident, then I’d probably suggest for you to learn something called Object Orientated Programming or OOP for short. OOP is simply where you create classes that can be reused over and over again in multiple scripts in your heart’s content. The reason why OOP is useful is simply because it can make code more organized, readable, and generally being more easier to manage.

If you read the little disclaimer from above, I highly suggest for you to not learn OOP until you learn modules, metatables, or Luau in general. Of course, there are multiple tutorials on how OOP works and how to implement it. Sorry if I accidentally made it confusing for you.

2 Likes

According to your reply so do you.

Just cache animation track somewhere
etc:

local anims:{[string]:AnimationTrack} = {}

local function GetAnimation(id:string):AnimationTrack
if anims[id]~=nil then return anims[id] end
local a = Instance.new("Animation")
a.AnimationId=id
local animation = animator:LoadAnimation(a)
anims[id]=animation
return animation
end

2 Likes

Ah, alright then. I might’ve overly complicated myself.

Thank you for helping me out :smile:

Is this still work even if the tool is different? like from shape and other thing

Yes it plays whatever animation you have, all you need to do is call GetAnimation(id : string) and i think animationId should be set like this, try both ways a.AnimationId = "rbxassetid://"..id

You could also type check it as a number rather than a string, then just do a.AnimationId = "rbxassetid://"..tostring(id)

1 Like

thank you so much for the help

as long as animation id you pass is the same yes.

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