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

why wont this script change parts parent?

Asked by
Benqazx 108
8 years ago
function a()
    local all = game.Workspace.Model:GetChildren()
    for i,v in pairs(all) do
        if v.ClassName == 'Part' then
            print('ClassName is part')
            if v.Material == 'Concrete' then
                v.Parent = game.Workspace.concrete
                print('worked')
            end
        end
    end
end
wait(3)
a()

this script is in workspace. i am just made this script to help me with alot of aprts. so basically i want this script to do is that if the classname of a thing in model is 'Part' and if the material of the part is 'Concrete' then that parts parent will me concrete which is a different model in workspace for all the concrete parts. this script will not change the parent of the concrete parts in the model

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
8 years ago

The only problem in your script was the fact that you tried to check if the Material was equal to a String. Material is used as an Enum, which is basically another data type. To fix your code, all you have to do is change line 6 to:

if v.Material == Enum.Material.Concrete then

So now your entire script should look like this:

function a()
    local all = game.Workspace.Model:GetChildren()
    for i,v in pairs(all) do
        if v.ClassName == 'Part' then
            print('ClassName is part')
            if v.Material == Enum.Material.Concrete then
                v.Parent = game.Workspace.concrete
                print('worked')
            end
        end
    end
end
wait(3)
a()

Anyways, I hope I helped. If you have any further problems/questions, leave a comment below, and I'll see what I can do.

0
ty it worked Benqazx 108 — 8y
0
no problem, glad I could help! dyler3 1510 — 8y
Ad

Answer this question