Any way to make this function shorter?

@NexoKami you should use @Inconcludable 's solution because it takes into account performance which I did take into account but didn’t implement because I was in a rush

That is true, but the main goal is to have fewer lines as possible.

Not sure why that is important but if it were, you could just compress all the code into one line:

local function AddItem(ClassName:string, Properties:{[string]: any})
   local obj = Instance.new(ClassName) for i,v in pairs(Properties) obj[i] = v end return obj
end

1 Like

It’s really not important. :sweat_smile:
But I’ll keep it in mind about it.

12 Replies later we get what was marked solution…

Ah yes, the exact same thing just with shorter variable names and type casting. Oh and I think the biggest reason: No new lines in the second argument. Anyways, have a good day to all of you

1 Like

Unfortunately, I couldn’t figure that one out xD

This should be at #help-and-feedback:code-review and not at #help-and-feedback:scripting-support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.