Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

My character isnt holding the entire tool. Help?(SOLVED)

Asked by 3 years ago
Edited 3 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

So i made a gun and put it inside a tool, i named the main part Handle and tested the game, but the handle was the only thing my character was holding; it wasn't holding another parts with the handle. How do i fix?

0
You need to have the other parts welded to the handle. You can use WeldConstraints to do it manually or use a plugin that will do it for you cowsoncows 951 — 3y
0
O Nifemiplayz 32 — 3y

1 answer

Log in to vote
0
Answered by
2Loos 168
3 years ago
Edited 3 years ago

Are the gun parts welded to the handle? Two methods. 1- Via manual welding process. Go to the 'model' tab and then select WeldConstraint. Then manually weld all your parts together. If you have too many parts, just move on to the next step. 2- Via script The following script should be a normal script under the tool.

for i,v in pairs(script.Parent:GetDescendants()) do
    if v:IsA("BasePart") or v:IsA("Part") or v:IsA("MeshPart") then
        local WELD = Instance.new('WeldConstraint')
        WELD.Parent = v -- Creates welds each time a part that isn't the handle is found.
        WELD.Part0 = v -- Creates a bond to the part
        WELD.Part1 = script.Parent:WaitForChild('Handle') -- Attaches the part to the handle.
        print(tostring(v.Name) .. "was welded to the handle. It shouldn't fall off now!")
    end
end

If you're wondering how this script works, it basically finds all the children and ancestors under the tool. Then, the script determines if the child is compatible with a weld. To work, it must be a BasePart, Part, or MeshPart. Afterward, it creates a new WeldContraint between the part and the Handle. The only issue with this script is an unnecessary weld between the handle and the handle itself. This shouldn't cause issues though. As for Weld.Part0 and Weld.Part1, those just define the two parts the weld should bond.

Ad

Answer this question