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

"return;" Command (or similar) in Lua?

Asked by 4 years ago
Edited 4 years ago

Hello fellow devs! I have a fairly simple question this fine, fine evening.

I know in JavaScript, you can use the

1return;

command to restart a for loop, etc.

I was wondering how I could do that with Lua.

My Code (The issue):

1-- This is wrapped in a bigger for loop.
2if (Part:IsA("Part")) == false or Part.Name == "Solid" then
3        print("Removed".. Part.Name)
4        break -- I have also tried "return".
5    end

Full code:

01local Model = script.Parent
02 
03wait(5)
04 
05for Model, Part in pairs(Model:GetChildren()) do
06    print(Part.Name)
07 
08    if (Part:IsA("Part")) == false or Part.Name == "Solid" then
09        print("Removed".. Part.Name)
10        break
11    end
12 
13    if Part.Shape == Enum.PartType.Block then
14        game.Workspace.Terrain:FillBlock(Part.CFrame, Part.Size, Enum.Material.Mud)
15    elseif Part.Shape == Enum.PartType.Cylinder then
View all 22 lines...

I'm either looking for another scriptinghelpers/DevForum link or an example.

Thanks in advance, Tim

0
Hello Tim! I was on your Roblox profile and you said you are a Christian trying to lead people to Jesus Christ, well, I am also a Christian doing the same thing! goodlead -62 — 4y
0
Also, where did you learn scripting so well. What did you do and who did you watch. goodlead -62 — 4y
0
@goodlead I'm self tough, mostly used sites like this and the lua library. ThatDevTim 188 — 4y
0
What is the lua library? goodlead -62 — 4y
View all comments (3 more)
0
Ohhh, so no youtubers you watched to learn like Alvinblox or TheDevKing? goodlead -62 — 4y
0
No, those tutorials are too direct. ThatDevTim 188 — 4y

1 answer

Log in to vote
-3
Answered by 4 years ago
Edited 4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
01local Model = script.Parent
02 
03wait(5)
04 
05function check(p)
06if not p:IsA("BasePart"or p.Name == "Solid" then
07        print("Removed".. Part.Name)
08        return true
09    end
10end
11 
12for Model, Part in pairs(Model:GetChildren()) do
13    print(Part.Name)
14 
15local checkstuff = check(Part)
View all 29 lines...

explanation was included in chat when this answer was provided.

Ad

Answer this question