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

My script that removes all welds from a part isn't working..?

		local RedStoneTa = script.Parent:GetChildren()
		local numberr = 1
		for i = 1,RedStoneTa[numberr] do
			numberr = numberr + 1
			local weldO = script.Parent:FindFirstChildWhichIsA("Weld")
			weldO:Destroy()
		end
		numberr = 1

My script is supposed to remove all welds from my part when a function occurs. This is the code inside the function.

2 answers

If you are running through tables like that its recommended to use for _,v in pairs(). It is more effective and is designed for that.

local RedStoneTa = script.Parent:GetChildren()
for _,v in pairs(RedStoneTa) do
	if v:IsA("Weld") then
		v:Destroy()
	end
end

The error occurred from line 3. You need to use :

for i = 1, #RedStoneTa[numberr] do

instead of using :

for i = 1,RedStoneTa[numberr] do

This is because :GetChildren() is a function of Instance.

Maybe it will work... I wasn't tested in on Roblox studio so I think it might work for you. :P

I hope you have a nice day, Bye!

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