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

Why does this only generate one frame?

Asked by 8 years ago

Lately a lot of things have been acting weird with the lua on roblox, maybe it's just me. The below script only generates one frame with the position of (20, 0, 1, 0). I'm sure its an error in the way im writing this, what I want it to do is generate 20x20 frames on the part. No error on the output, otherwise I wouldn't be asking for help.

frame = workspace.part.SurfaceGui.Frame
tile = Instance.new("Frame")
tile.BorderSizePixel = 1
tile.Size = UDim2.new(.05, 0, .05, 0)
for i = 1, 20 do
    for u = 1, 20 do
        tile.Parent = frame
        tile.Position = tile.Position + UDim2.new(0.05, 0, 0, 0)
    end
    tile.Position = tile.Position + UDim2.new(0, 0, 0.05, 0)    
end

I'm running this from the command bar.

1 answer

Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
8 years ago

It only generates one frame because the frame is instantiated before the loop. In your snippet, the loop only updates the position of the already created frame.

The following would only change the Name property of part x to the corresponding value or i. . while simply moving the first line into the for-loop would create multiple parts with different names.

-- [1]
x = instance.new("Part")

for i = 1, 20 do
    x.Name = i
end

-- [2]
for i = 1, 20 do
    x = instance.new("Part")
    x.Name = i
end

In your case, you want to do something similar to the second example.

frame = workspace.part.SurfaceGui.Frame

for i = 1, 20 do
    for u = 1, 20 do
    tile = Instance.new("Frame")
    tile.BorderSizePixel = 1
    tile.Size = UDim2.new(.05, 0, .05, 0)
        tile.Parent = frame
        tile.Position = tile.Position + UDim2.new(0.05, 0, 0, 0)
    end
    tile.Position = tile.Position + UDim2.new(0, 0, 0.05, 0)    
end
0
Thank you, I should have known that, obviously the frame was only created one time with my previous code. magiccube3 115 — 8y
Ad

Answer this question