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

why wont this script change parts parent?

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

✓ Accepted answer

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.

2 comments

0

ty it worked

0

no problem, glad I could help!

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