-- This is maybe a representation
--[[Option1]]--
if condition then
-- do something
return
end
-- do something else
--[[Option2]]--
if condition then
-- do something
else
-- do something else
end
Option 1 would be quicker as the interpreter doesn’t have to check the else statement, it also reduces the size in memory of the abstract syntax tree.
Although it would be a negligible amount of difference between the two options, I would personally prioritize which one you can read better, in my opinion that’s option 1 again.
local function attachmentPreview()
local mouseLocation = UserInputService:GetMouseLocation()
local unitRay = camera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
local cast = workspace:Raycast(unitRay.Origin, unitRay.Direction * 1000, CastParams)
if cast and attachPreview then
outline.Adornee = cast.Instance
attachPreview.Position = toGrid(cast.Position)
AttachmentArrows:PivotTo( CFrame.new(attachPreview.Position) )
updatePropertiesBarTextToSomething(attachPreview.CFrame, cast.Instance.Name)
return
end
updatePropertiesBarTextToBlank()
-- Would putting a "return" here be nessesary? Would it be faster? Thanks!
end
I would suggest NOT to add a return as it clutters up the code, unless you’d want to return false at the end and return true inside the if statement just to indicate that the method passed successfully.