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

why doesen't the for loop work but the rest of the script does?

Asked by 5 years ago
Edited 5 years ago

so in the script in the script i did this, it printed gamestart but didn't print yes, the rest of the script works just that this for loop doesn't work

001while true do
002    num = nil
003    print ("gamestart")
004    for _,i in pairs(game.Players:GetPlayers())do
005        print ("yes")
006        if i.CanPlay.Value == true then
007            print ("canplay")
008        if num == nil then
009            num = 0
010        end
011 
012        num = num+1
013    local Number = Instance.new("IntValue")
014    Number.Parent = i
015    Number.Name = ("PlateNumber")
View all 123 lines...

it outputs:

1gamestart
2getting BasePlate
3getting players 2
4canplay 2
5getting character 2 (x14)
6got character 2
7getting platenumber (x6)
0
You have to put ends. cmgtotalyawesome 1418 — 5y

2 answers

Log in to vote
1
Answered by
ArtBlart 533 Moderation Voter
5 years ago

The script get trapped inside the loop. In order to get out of it, you need a break at the bottom of your loop. Here's an example of this:

1while true do wait()
2    print("hi")
3end
4 
5--will get stuck above
6 
7print("done")

OUTPUT: "hi"

note that it would print an infinite amount of times

and with a break:

1while true do wait()
2    print("hi")
3    break
4end
5 
6print("done")

OUTPUT: "hi", "done"

0
that doesen't look like the problem i'm having flireferret 26 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

the wait at the end was mispaced looping the for loop too many times

Answer this question