Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

7 comments

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!

0

Also, where did you learn scripting so well. What did you do and who did you watch.

0

@goodlead I'm self tough, mostly used sites like this and the lua library.

0

What is the lua library?

0

Ohhh, so no youtubers you watched to learn like Alvinblox or TheDevKing?

0

No, those tutorials are too direct.

1 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.

This discussion is preserved as it was. New answers, comments, and votes are closed.