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

my loop doesnt work?

Asked by 6 years ago
Edited 6 years ago

im just a newb that tries to code so for training i made a loop that makes grow the block every second. but after first one it stops. why it isnt looping?

local x = 1
local y = 1
local z = 1
local tag = Instance.new("Part")
tag.Name = "Block"
tag.BrickColor = BrickColor.new("Bright red")
tag.Material = "Wood"
tag.CanCollide = true
tag.Parent = workspace
tag.Position = Vector3.new(0,10,5)
tag.Size = Vector3.new(x,y,z)
local loop = 1
while (loop >= 1) do

  wait(1)

tag.Size = Vector3.new(x ,y + 1 ,z )    

end
0
the loop works but saying "y+1" doesn't change anything. you would have to say y=y+1. if y was 2, you are like constantly asking "what is 2+1, what is 2+1..." but its always 3. refer to the answers. cabbler 1942 — 6y

3 answers

Log in to vote
0
Answered by
Lolnox 47
6 years ago

Just write

while true do
    y = y + 1
    wait(1)
    tag.Size = Vector3.new(x, y, z)
end
Ad
Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

Variable 'Y' is constant and it'll always be 1.

Here's what you can do to resolve this problem:

-- By the way, since you want the loop to be infinite, you could also use the condition as true, which makes it loop infinitely.

while (true) do
      wait(1)
      y = y + 1
      tag.Size = Vector3.new(x, y, z)
end
Log in to vote
0
Answered by 6 years ago

thanks for all answers. will keep working for being good coders like you

Answer this question