-- Create Floor
local h = 0 while h < 5 do wait() local x = 0 local y = 5 local z = 0 z = z * 2 local g = 1 local PartZ = Instance.new("Part", game.Workspace) PartZ.Size = Vector3.new(4,1,4) PartZ.Position = Vector3.new(x,y,z) z = z + 4 PartZ.Name = g g = g + 1 PartZ.Anchored = true h = h + 5 end
Not in Code:
Only one part tends to generate from instance.new(). I would like help understanding why my code does this. I am only generating parts on the z axis, so please help me.
:)
Re-edited by JC/JesseSong
You shouldn't create the variables inside of the while loop because the variable can now only be used inside the loop. This means when the loop runs again, it cannot access the new values of x,y and z. The value of x, y, and z will be the starting value you assigned them to be causing them to all be in the same position. Putting the variable on the outside will allow the entire loop and other code to access the same variable. So instead of putting it in the inside
while true do local x = 5 -- other code end
Put it outside of the loop
local x = 5 while true do -- other code end