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

I'm trying to change the size of all of the bricks in a model. Why doesn't it work?

a = game.Workspace.Map:GetChildren()

script.Parent.Touched:connect(function()
	if script.Parent.Parent.Touched.Value == 0 then
		script.Parent.Parent.Touched.Value = 1
			wait(25)
				for index,v in pairs(a) do
					for i = 1,625 do
						local s = math.random(2,6)	
					v.Size = Vector3.new(4,s,4)
				wait(.005)
			end
		end
	end
end)

The variable a should work as expected. The model is called Map. The numbervalue thing is a parent of the parent of the script, so that works. I think I'm having trouble with the in pairs part.

1 answer

You should start by fixing your tabbing so that it is easy to read your code:

a = game.Workspace.Map:GetChildren()

script.Parent.Touched:connect(function()
	if script.Parent.Parent.Touched.Value == 0 then
		script.Parent.Parent.Touched.Value = 1
		wait(25)
		for index,v in pairs(a) do
			for i = 1,625 do
				local s = math.random(2,6)  
				v.Size = Vector3.new(4,s,4)
				wait(.005)
			end
		end
	end
end)

I'm not sure why you are using a IntValue when you could just be using a variable:

numberTouched = 0

...

numberTouched = 1


The minimum amount of time that wait is allowed to wait is about .034 seconds, which is 7 times slower than the amount you are trying to wait.

Your code attempts to resize each part individually 625 times, then moves onto the next part. Each part would take about a third of a minute, then.

If there are other objects in Map other than parts (e.g., Scripts, Models), though, you'll have a problem -- because they don't have a Size property.

You should check that v:IsA("BasePart") to ensure that v is in fact something that can be resized.


You should be using better variable names. a is a bad name for the list of objects in a map. Just say map or mapChildren or some other useful variable name.

3 comments

0

It like my things like pyramids like that.

0

I did what you said, but it just kept changing the the size of one block, not all 625.

0

You didn't read what I said then. Because I said that you have that set up wrong

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