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

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

Asked by 10 years ago
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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

0
It like my things like pyramids like that. Lightdrago 95 — 10y
0
I did what you said, but it just kept changing the the size of one block, not all 625. Lightdrago 95 — 10y
0
You didn't read what I said then. Because I said that you have that set up wrong BlueTaslem 18071 — 10y
Ad

Answer this question