Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why do my i,v in pairs weld tool scripts never weld the parts i want to weld properly? [read me]

I know the typical weld script using iv pairs in a tool, however it never works and is kind of angering me. why???? pls

for example of the typical weld script

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA('BasePart') then
		local weld = Instance.new('Weld', v)
		weld.Part0 = v
		weld.Part1 = script.Parent.Handle
		weld.C0 = v.CFrame:inverse()
		weld.C1 = script.Parent.Handle.CFrame:inverse()
	end
end

PLEASE TELL ME WHAT I COULD BE DOING WRONG

2 answers

From the looks of your code, it's set to also weld your tool's Handle as well, which may(?) cause some problems(?) I'd also recommend using a variable for the Handle, rather than re-typing the same thing over-and-over again:

local HandleVariable = script.Parent:WaitForChild('Handle') -- WaitForChild is a function that waits until a child w/ the same name as the argument is within the designated 'Parent;' variable "HandleVariable" represents the Handle

Now, w/ that, we'll make some changes, and remove those long lines of unnecessary code:

local HandleVariable = script.Parent:WaitForChild('Handle')

for i, v in pairs(HandleVariable.Parent:GetChildren()) do -- Get all the children that is within the Handle's parent
	if v:IsA('BasePart') and v ~= HandleVariable then -- If the object is a part, and isn't the Handle, then...
		local weld = Instance.new('Weld', v)
		weld.Part0 = v
		weld.Part1 = HandleVariable
		weld.C0 = v.CFrame:inverse()
		weld.C1 = HandleVariable.CFrame:inverse()
	end
end

Now, since I haven't played ROBLOX in months, I'm going to theorize that weld's properties C0 & C1 are the problem(s); I remember a similar problems like this a while ago, and if memory doesn't fail, I multiplied the part's actual CFrame by the inversed CFrame:

weld.C0 = v.CFrame:inverse() * v.CFrame
weld.C1 = HandleVariable.CFrame:inverse() * HandleVariable.CFrame -- My memory is pretty foggy, but I believe it was like this; I forgot why it's necessary though, so I apologize in advance if this is wrong

Now, our final result is this:

local HandleVariable = script.Parent:WaitForChild('Handle')

for i, v in pairs(HandleVariable.Parent:GetChildren()) do
	if v:IsA('BasePart') and v ~= HandleVariable then
		local weld = Instance.new('Weld', v)
		weld.Part0 = v
		weld.Part1 = HandleVariable
		weld.C0 = v.CFrame:inverse() * v.CFrame
		weld.C1 = HandleVariable.CFrame:inverse() * HandleVariable.CFrame
	end
end

Your question doesn't give a lot specifics or information, so I'm going off on a whim this time on what the problem could be; next time, could you please give more information on the problem, i.e. did you use prints? Did they all work? Was there any error feedback in the Output? If so, what did it say? And can you give us what it said? etc. :)

I hope this helped somehow, as I haven't played in months. :D

6 comments

0

My gut is telling me I'm wrong. >.<

0

you've gotten somewhere because the parts actually weld... but C0 and C1 are incorrect as you have it. C0 and C1 are incorrect as i had it too.

0

Ah, so that was the problem? Switching the two CFrames? :P

0

yes. Thankyou btw, now i can play around w/ welding. I really want to weld a ninja star that i made and script the tool.

0

Ok, and np man. :) Good luck on your Ninja Star! :D Haiiiii-YAAAH!!! >||(o_o)

0

This seems very tedious especially for multi parted tools.

You can go about this multiple ways. The easiest by far is solid modeling. Just take a few parts select them all and hit union and there you go. Alternatively you can use a plugin that creates Moter6D's or welds. Then weld the primarypart of the model to the handle of the tool and use Motor6Ds for the main model. Everytime the model's parent is changed, you use the function MakeJoints() to make them stick together.

2 comments

0

I wish i could csg (solid model) all if the stuff together but that didnt work, but the plugin does interest me bcuz im desperate.

0

If I'm not using solid modeling then this is what I use along with the plugin. It's really easy, man. Also about solid modeling, you probably need to go in and union them two by two or something.

This discussion is preserved as it was. New answers, comments, and votes are closed.