Hey!
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
print("starting")
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)
animationTrack:Play()
return animationTrack
end
end
end
end)
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!
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
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
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
yourToolModel:SetPrimaryPartCFrame(handle.CFrame)
--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
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