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

My Tool Welding Script which should automatically weld is broken?

Asked by 7 years ago
Edited 7 years ago

The Problem is: The script doesn't weld the tool, but I have seen it work before, it 's just not working for me, it doesn't weld and it doesn't let the player use it, so the player doesn't hold it, it just falls through the ground where I make it :( I have a very, very, basic tool, consisting of 6 parts, the reason I don't want to make it too complex is because, I want to learn how to script my own gun, so Im using designs that aren't too complex. (I have made and developed more complex tools with over 200 parts) but I used a free script to help me (yeah, I'm quite a new scripter), The first part im aware of to making a usable tool (its meant to be a gun, I'm working on a game) is to start with welding and slowly get into more difficult scripts. Here is the script;

local Gun = script.Parent

local Handle = Gun:WaitForChild("Handle")
local INSERT = table.insert
local Parts = {}
spawn(function()
    for _,v in pairs(Gun:GetChildren()) do
        if v:IsA("BasePart") and v ~= Handle then
            if v:FindFirstChild("MainWeld") then v.MainWeld:Destroy() end
            if (not v:FindFirstChild("WeldCF")) then
                local WeldCF = Instance.new("CFrameValue")
                WeldCF.Name = "WeldCF"
                WeldCF.Value = Handle.CFrame:toObjectSpace(v.CFrame)
                WeldCF.Parent = v
            end
            INSERT(Parts, {Obj = v, Weld = nil})
            v.Anchored = false  
        end
        Handle.Anchored = false
    end
end)

The parts inside the tool are as follows: A normal script - "WeldTest" A part, used as handle or hold part - "Handle" A normal Part - "P1" A normal Part - "P2" A normal Part - "P3" A normal Part - "P4" A normal Part - "P5" thank to help
EDIT:

local akm = workspace.AKM

function Weld(A, B)
    for i,v in pairs(A:GetChildren()) do
        if v:IsA("BasePart") then
            if v ~= B then
                local weld = Instance.new("Weld")
                weld.Part0 = B
                weld.C0 = B.CFrame:inverse()
                weld.Part1 =  v
                weld.C1 = v.CFrame:inverse()
                weld.Name = v.Name
                weld.Parent = B
            end
        end
    end
end

akm.Handle.Anchored = true
Weld(akm, akm.Handle)  
--Use this script instead :)

1 answer

Log in to vote
0
Answered by 7 years ago

Try this script. You don't need to need to change anything, just place it inside of your tool.

WeldParts = script.Parent:GetChildren()
for i=1, #WeldParts do
if WeldParts[i]:IsA("Part") or WeldParts[i]:IsA("UnionOperation") or WeldParts[i]:IsA("MeshPart") then
if WeldParts.Name ~= "Handle" then
local weld = Instance.new("Weld", script.Parent.Handle)
weld.Part0 = script.Parent.Handle
weld.C0 = script.Parent.Handle.CFrame:inverse()
weld.Part1 =  WeldParts[i]
weld.C1 =WeldParts[i].CFrame:inverse()
end
end
end
0
I also get this http://imgur.com/a/THjpJ abnotaddable 920 — 7y
0
I accidently disabled the script, heres the actual error; http://imgur.com/a/uLVSw abnotaddable 920 — 7y
0
I accidentally anchored a part here is what it looks like now ... http://imgur.com/a/0mFZc abnotaddable 920 — 7y
View all comments (2 more)
0
never mind, I got it to work, was just the rotation of the handle abnotaddable 920 — 7y
0
If it worked, please accept my answer. Precisionly 103 — 7y
Ad

Answer this question