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

Why will my script not stop looping?

Asked by 10 years ago

I am basically making an update log that has SurfaceGui's and you'll have to click a button, causing the part to move up from the ground into view. If more information is needed, Comment please.

Regular Script:

01OpenedOrClosed = game.Workspace.UpdateLog["Open/Closed"].Value
02bool = true
03--213, 169.4, 62
04 
05--213, 180.4, 62
06script.Parent.MouseButton1Click:connect(function()
07    if OpenedOrClosed == "Closed" then
08        local Updatelog = game.Workspace.UpdateLog
09        while bool == true do
10            Updatelog.CFrame = Updatelog.CFrame * CFrame.new(0,0.1,0)
11            wait(0.01)
12            if Updatelog.CFrame == CFrame.new(213, 180.4, 62) then
13                bool = false
14                OpenedOrClosed = "Opened"
15            end
View all 29 lines...
0
When I click this, it does rise up but never stops. alphawolvess 1784 — 10y
0
What I can already tell you is that wait(0.01) is the same as wait(), since 0.03 is the minimum argument for wait(). aquathorn321 858 — 10y

2 answers

Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
10 years ago

Your code indentation is erroneous and hence it is harder to observe that you have mismatched ends.

I don't understand why, on line 12, you return if the condition is true. I don't think you meant to type that, but rather:

1if Updatelog.CFrame == CFrame.new(213, 180.4, 62) then
2      bool = false
3      OpenedOrClosed = "Opened"
4end

It's difficult to understand what a lot of your code is supposed to do. At the moment, it continually loops because (I'm guessing) in the second loop, the condition "bool == false" is never reached.

It may be that you only want to trigger the Opened/Closed behaviour separately, in which case you can use an elseif check (on line 18) rather than plain if; that way, when the user clicks, only the code for 'Opened' or 'Closed' will be triggered, but not both.

Another minor point is that, when dealing with boolean values in conditions, someVariable == true is the same as writing someVariable and `someVariable == false' is the same as writing 'not someVariable'. So, for example, your while loop on line 9 could be written:

1while bool do
2--code
3end

Summary

  • Indent your code properly. This will help you identify mismatched ends and will help others be able to read your code easier.
  • Think about if you need to use if or elseif
  • In future questions, try and explain what is supposed to happen in more detail
0
Sorry, I accidentally copied a mess up I did and fixed in game. I'll remove that return end problem alphawolvess 1784 — 10y
Ad
Log in to vote
-3
Answered by 10 years ago

Just Saying but i think it does not like the line

1while bool == true do

Because it mite think that your saying while true do

while true do loops stuff.

0
Incorrect: The 'while ARG do' loop, for it's Argument, will run while it's Argument stays/is true, but when it's Argument becomes false to it, it will stop the loop. TheeDeathCaster 2368 — 10y

Answer this question