Attempt to call a Instance value

Alright @Downrest, calm it down a notch we can emphasize without sounding angy.

Well, yes. You did… The difference between what you want to happen and what happened is that:

  • Instance.new() is a function itself, which returns a <Variable>Instance (Variable in the sense of many Instances)

  • When you required CodeModule, you’re evaluating the CodeModule table and all of its members.

  • Due to the fact it’s evaluated and it’s not a callable member (function/closure), it is taken for its face value, which in this case, is the return of the method .new() from Instance.

  • Now in the case of the code I provided you, there’s a closure wrapping around Instance.new() that requires it to be called by external means, and it isn’t evaluated to execution immediately.

Anyways, hope the lesson helped to wrap your head around it.

Cheers,
IDoLua

Heh, sorry. I just wanted to emphasize what I mean.

Ok, one last question then. Do I need to say return because I accidentally left it out but it still ran?

Return where, like at the end of the module?

It’s not neccessary every time, no.

Return just means your function provides something. (In your case reference to an object for InsertAPart)

Inside the functions.

Yeah because if I say return TestGameObjects.Part.Anchored = true then it errors.

InsertAPart = function()
        return Instance.new("Part", workspace)
    end

When you run InsertAPart(), it returns a part right?


return TestGameObjects.Part.Anchored = true

This line of code already runs in itself, no need for adding return.

1 Like

That’s because you’re setting a Variable, not getting.
If you add another = sign there, you would be effectively doing: (Pseudocode [Logical])

return: is Part in TestGameObjects currently Anchored

1 Like