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

return;

command to restart a for loop, etc.

I was wondering how I could do that with Lua.

My Code (The issue):

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

Full code:

local Model = script.Parent

wait(5)

for Model, Part in pairs(Model:GetChildren()) do
    print(Part.Name)

    if (Part:IsA("Part")) == false or Part.Name == "Solid" then
        print("Removed".. Part.Name)
        break
    end

    if Part.Shape == Enum.PartType.Block then
        game.Workspace.Terrain:FillBlock(Part.CFrame, Part.Size, Enum.Material.Mud)
    elseif Part.Shape == Enum.PartType.Cylinder then

    elseif Part.Shape == Enum.PartType.Ball then
        game.Workspace.Terrain:FillBall(Part.Position, Part.Size.X/2, Enum.Material.Air)
    end
    Part:Destroy()
    wait()
end

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.
local Model = script.Parent

wait(5)

function check(p)
if not p:IsA("BasePart")  or p.Name == "Solid" then
        print("Removed".. Part.Name)
        return true
    end
end

for Model, Part in pairs(Model:GetChildren()) do
    print(Part.Name)

local checkstuff = check(Part)
if checkstuff then
return
end

    if Part.Shape == Enum.PartType.Block then
        game.Workspace.Terrain:FillBlock(Part.CFrame, Part.Size, Enum.Material.Mud)
    elseif Part.Shape == Enum.PartType.Cylinder then

    elseif Part.Shape == Enum.PartType.Ball then
        game.Workspace.Terrain:FillBall(Part.Position, Part.Size.X/2, Enum.Material.Air)
    end
    Part:Destroy()
    wait()
end

explanation was included in chat when this answer was provided.

Ad

Answer this question