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

This repeating script keeps breaking on repeat, what do I do?

Asked by
higzl 17
7 years ago

It always breaks on the third line and I no idea why it does it, I don't know if there is something wrong with Until or the equal signs. If you wonder what this script is, its a floating script.

w = 0
while wait() do
repeat until W == 20
    script.Parent.Position = script.Parent.Position + Vector3.new(0, 0.1, 0)
    W = W + 1
    print(W)
repeat until W == 60
    script.Parent.Position = script.Parent.Position + Vector3.new(0, 0.01, 0)
    W = W + 1
    print(W)
repeat until W == 40
    script.Parent.Position = script.Parent.Position + Vector3.new(0, -0.01, 0)
    W = W - 1
    print(W)
repeat until W == 20
    script.Parent.Position = script.Parent.Position + Vector3.new(0, -0.1, 0)
    W = W - 1
    print(W)
repeat until W == 0
    script.Parent.Position = script.Parent.Position + Vector3.new(0, 0.01, 0)
    W = W - 1
    print(W)
end


0
You are repeating nothing, so do repeat wait() until thehybrid576 294 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Well, you made a big mistake. If you say "repeat until" you are telling it do nothing until it hits the certain until mark. Here is how you should make your code to fix it

W = 0
while wait() do
repeat
    script.Parent.Position = script.Parent.Position + Vector3.new(0, 0.1, 0)
    W = W + 1
    print(W)
    wait()
until W == 20
repeat
    script.Parent.Position = script.Parent.Position + Vector3.new(0, 0.01, 0)
    W = W + 1
    print(W)
    wait()
until W == 60
repeat
    script.Parent.Position = script.Parent.Position + Vector3.new(0, -0.01, 0)
    W = W - 1
    print(W)
    wait()
until W == 40
repeat
    script.Parent.Position = script.Parent.Position + Vector3.new(0, -0.1, 0)
    W = W - 1
    print(W)
    wait()
until W == 20
repeat
    script.Parent.Position = script.Parent.Position + Vector3.new(0, 0.01, 0)
    W = W - 1
    print(W)
    wait()
until W == 0
wait()
end

This script fixes the breaking. Here is the explanation:

The repeats were breaking for 2 reasons:

They were repeating for nothing
They had no wait time, running it at a pace LUA could not handle

Next time, try putting a wait inbetween. Using wait() will work, because waiting 0 seconds is still a time frame to lua

0
Lol sorry for the inline code accident at the explanation XD UnreadyHappiness 35 — 7y
Ad

Answer this question