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

Why does this only generate one frame?

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

✓ Accepted answer

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

1 comment

0

Thank you, I should have known that, obviously the frame was only created one time with my previous code.

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