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

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

Asked by
N43FGXL 169
5 years ago
        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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
5 years ago

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!

Answer this question