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

Attempt to Destroy Welds Failed?

Asked by
Omzure 94
4 years ago
Edited 4 years ago

a splitter script where when touched will destroy any welds in the part that touched it

return function()
    script.Parent.Touched:Connect(function(t)
        if t.Name == "Pushbox" and t.Parent.Name or t.Parent.Parent.Name == "DualityPushboxSpawnButton" then --seeing if the part touched is named 'pushbox and the parent's name of the pushbox is 'DualityPushboxSpawnButton' 
            for i,v in pairs(t.Parent or t.Parent.Parent) do
                if v.Name == "WeldConstraint" or "Weld" then
                    v:Destroy() -- seeing if the dualitypushboxspawnbutton contains any welds, and destroys them
                end
            end
        end
    end)
end

Image of what will be touching the splitter

https://gyazo.com/75e3ba528847c1466eb4d6aa01c2265f

Image of error

https://gyazo.com/1f04231c9332631f14af8510b167c171

1 answer

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

The problem is that you're directly referencing the Object without calling GetChildren(). The pairs function expects you to input a table (which is what GetChildren() returns) but you're instead inputting an instance object (t.Parent and t.Parent.Parent), hence the error.

Fixing this is quite easy.

return function()
    script.Parent.Touched:Connect(function(t)
        if t.Name == "Pushbox" and t.Parent.Name or t.Parent.Parent.Name == "DualityPushboxSpawnButton" then
            for i,v in pairs(t.Parent:GetChildren() or t.Parent.Parent:GetChildren()) do -- Now the script uses the object's children instead of the object directly.
                if v.Name == "WeldConstraint" or "Weld" then
                    v:Destroy() destroys them
                end
            end
        end
    end)
end
Ad

Answer this question