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

If statement not working and while loop just restarts?

Asked by
CodeWon 181
4 years ago
Edited 4 years ago

The script I made is supposed to detect when there are no more items in a folder, its in a while true do loop. But the loop completely restarts and doesn't do anything when all the items are collected. Whats wrong?

01while true do -- this loop is inside of another loop
02    local Gems = ClonedMap.Gems
03 
04    local player = game.Players.LocalPlayer
05 
06    if not Gems:FindFirstChild("Gem") then -- This is supposed to check if there are any items (gems) in the folder
07 
08        wait(1)
09 
10        Status.Value = "All gems have been found, game over!"
11 
12        wait(1)
13 
14 
15        player.Character:BreakJoints() -- Resets players when all gems are found, this  part also doesn't work
View all 21 lines...

1 answer

Log in to vote
1
Answered by 4 years ago

You could try making a variable that the while true do runs on, for example:

01local gemsFound = false
02 
03while not gemsFound do -- this loop is inside of another loop
04    local Gems = ClonedMap.Gems
05 
06    local player = game.Players.LocalPlayer
07 
08    if not Gems:FindFirstChild("Gem") then -- This is supposed to check if there are any items (gems) in the folder
09 
10        wait(1)
11 
12        Status.Value = "All gems have been found, game over!"
13 
14        wait(1)
15 
View all 23 lines...
0
Everything works, except for line 17-Attempt to index nil with 'Character' how can I fix this? CodeWon 181 — 4y
0
Well, if this is a server script you can't get the local player MOREHOURSOFFUN 104 — 4y
Ad

Answer this question