How Do i play an animation on an weapon, character in a single animation?

Hello!
I’ve been trying to make an animated weapon, and i wanted to make the character play an animation And the weapon to unfold with the same animation. I connected the weapon’s body attachment (Basically the torso of the weapon) to character’s right arm. I’ve made an animation of the character unfolding the weapon, but i don’t know how to load the animation in both the character and weapon.
Here’s some more information if needed:


image

If you need anything else to know about let me know!
All help will be appriciated!

1 Like

So, you’re on the right track with it having an Animation Instance within the tool to help set it up.

To help load the animation for the player, you’ll need to put the ID of said animation into the Animation Instance. Then, you can use a LocalScript to load the animations.

local Humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
local Animation = script.Parent.Animation

if Humanoid and Humanoid.Health < 0 then

   local Animator = Humanoid:FindFirstChild("Animator") or Humanoid
   local PlayAnim = Animator:LoadAnimation(Animation)

   PlayAnim:Play()
end

You can use this batch of code within your local script to attach to an Equipped Event, which would look like this:

script.Parent.Equipped:Connect(function()

local Humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
local Animation = script.Parent.Animation

if Humanoid and Humanoid.Health > 0 then

   local Animator = Humanoid:FindFirstChild("Animator") or Humanoid
   local PlayAnim = Animator:LoadAnimation(Animation)

   PlayAnim:Play()
end
end)

For animating the weapon, you’ll need to know how to Tween the CFrame of the Tool’s GripPosition. I recommend you making two Vector3 Variables. One for the equipped and the other for unequipped.

1 Like

There is no grip on the weapon, it’s a handleless weapon, the body attach part can get moved in the animator, will that not do the work? Instead of using CFrames?
Asking cause im not too good at those.

If the body attach part is welded to every other part then yeah, it should work.

You’d have to still CFrame the part though, atleast the Orientation of it. It could be easier if you just welded the part to the player, but it might not give the correct orientation. I’m just saying, and what I mean by CFraming the part it’s actually CFraming the weld of the part.

Oh, I see. Alright, il try that!

Let me (us) know what happens!

Of Course, Thanks for the motivation to help me!

1 Like

Also, is there a way to make the animation play server-side?

Local scripts should be able to play it serversided since it’s using the humanoid (perferably the Animator in the humanoid) to play the animation. So it’ll send that animation across to everyone that’s in the game to see.

You’re welcome! If there’s anything else you need you have DevForum, or if you want to you can contact me in PM’s.

Bumped, I realized that I’ve had mistaken the greater than sign and instead put a less than sign. Woops!

Hm, i’ve tried the suggesting you gave me, there are no errors, but the animation did not play, i did move the Arm4 part (and the entire model) away from the BodyAttach, do i have to make another animation if i moved it?

How does your script look for the moment?

The model looks like this:
image

And the LocalScript looks like this:

Incase, il also send how the server-side script looks like:

Does the animation have the a set ID?
It might be also on the local Animator line, remove the “or Humanoid” and see if that does anything

The Animation does have an ID, I will try to remove the Or Humanoid and see what happends

1 Like

Didn’t work, i tried to make the animation play on a activation of the tool, and typed on the end of “If”, print(“Script Made It All The Way To The End”). But when i clicked, the text didn’t print in the output, that could mean that one of the “If” Requirements are not true.

OH, CHANGE THE < TO A > (that’s almost a common mistake for me; especially when I’m coding with a very sleepy mentality).

1 Like

Ah! There we go! Now it works! Only one of the parts in the model moves but that’s probably because i’ve changed it’s position, so i have to redo the animation. But thank you very much! I owe you one!

1 Like