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

Can while true do be used in a function?

Asked by 8 years ago
Edited 8 years ago

I'm trying to make a script which when the brick is clicked it moves, although I don't know how to connect <while true do>

while true do
    script.Parent.Position = script.Parent.Position + Vector3.new(0,0,0.1)
    wait(0.1)
end

script.Parent.ClickDetector.mouseClick:connect()-- I don't know what to put here.

In the () I normally put the name of the function I need to call. But when I use a <while true do> how do I call the script?

Then I tried to do this

function move()
    script.Parent.Position = script.Parent.Position + Vector3.new(0,0,0.1)
    wait(0.1)
end

script.Parent.ClickDetector.mouseClick:connect(move)

But then it only moved once each time I clicked, but I'm not sure if you can put a while true do in a function?

1
You most definitely can put a while loop inside a function, and anything else for that matter -- even other functions :) nicemike40 486 — 8y
0
Oh, thanks. EasilyTech 25 — 8y
0
Be aware that if it's "while true do", your script will only exit the loop if you have a break statement inside it that executes. GoldenPhysics 474 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Yes, you can place anything in a function
If the boot fits...

Functions are just, for beginners, a convenient way to get code from another part of the script to run when you want it. This can be from an event, or when you call it yourself somewhere else in your code.

Ad

Answer this question