Why isn't this working?

I’m making animations for my gun and it’s not only staying there (Not being held) it also doesn’t move for the animation
robloxapp-20220204-1932522.wmv (2.7 MB)
The code that handles it (localscript inside the tool)

local Player = game:GetService("Players").LocalPlayer
local CharacterAdded = Player.Character or Player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local Character = Player.Character
UIS.InputBegan:Connect(function(Input, GP)
	if Input.KeyCode == Enum.KeyCode.R and not GP then
		local humanoid = Character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			local Animation = Instance.new("Animation", humanoid)
			Animation.AnimationId = "rbxassetid://8725074606"
			local animator = humanoid:FindFirstChildOfClass("Animator")
			if animator then
				local animationTrack = animator:LoadAnimation(humanoid.Animation)
				return animationTrack
1 Like

Try adding print commands to see where it fails.

1 Like

The code itself works. Watch the video, you’ll see what I mean.

my tip were, you should’ve add a weldconstraint, that might be working. add a weldconstraint between right or left arm, with the weapon.

maybe that works.

1 Like

Not useable. Animations on tools require M6D and welds, interfering with things like that would break the animations even more.

huh? that’s weird. didn’t noticed that. .-.

Is the M6D correctly connected to the character?
You would have to add a script that creates an M6D and attaches it to the player’s character.

I am pretty new to this, but I think you need the weapon model or handle of it called “Handle”. Then it should connect to your hand. Not sure if you have this or not!

This is not present because again, enabling use handle would break animations.

Not solved. Here’s the tool properties:

You may have better luck with creating your own custom tool instead of using the Roblox tool instance

How exactly would this be done? I think there is a much better idea, this would not only put me under too much pressure, use CoreGuis in some method, it’s a waste of time and effort. I think that it’s impossible to do that, anyways.

Well, it’s not exactly impossible and I believe there are some custom tool modulescripts floating around too, but yes, on second thought, perhaps that is too much to deal with.

The only thing else I can think of is to either:
A.) Create an invisible handle and WeldConstraint your real tool to the handle (make sure to set CFrame to the handle’s)
B.) Do the same thing as above but without a handle

Not sure what you mean. Animations need M6D or it doesn’t work. This is the tutorial that kind of explains it:
Tutorial - Animate tools

No, no, you misunderstood. You would still have the Motor6Ds of the tool, you only need to weld one part of the tool to the invisible handle. You don’t have to replace any Motor6Ds

Can you help? I don’t understand. I think you can’t use a handle, anyways.

Okay, here, I will make some pseudocode of a localscript (may not work fully, but should help give an idea):

local Player = game:GetService("Players").LocalPlayer
local CharacterAdded = Player.Character or Player.CharacterAdded:Wait()
local Character = Player.Character

--Get the tool and then get the model of your tool you are using.
--If you do not have your tool part(s) wrapped in a model, it's a good idea to do so. Make sure to set the Model.PrimaryPart to a part that stays static and has no animations on it
local tool = script.Parent
local yourToolModel = tool["YourToolModelGoesHere"]

--Create a handle (make sure to have UseHandle checked on the tool)
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Transparency = 1
handle.CanCollide = false
handle.Size = Vector3.new(0.1,0.1,0.1)
handle.Parent = tool

--Line up the model with the handle

--Makes the tool model attach to the handle with a WeldConstraint
local newWeld = Instance.new("WeldConstraint")
newWeld.Part0 = handle
newWeld.Part1 = yourToolModel.PrimaryPart
newWeld.Parent = handle

Would it be a localscript or serverscript?

Localscript. Keep in mind, it may or may not work, I just wrote it off the top of my head to give a rough idea.

Make sure to read the comments because they explain what everything is doing

1 Like

I get this:

Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this. - Client - LocalScript:19