Help with an OOP problem

This is attempting to index nil with ‘PrimaryPart’ How can I fix?

  local function GET_DISTANCE(instance: Model, target: Model)
return (instance.PrimaryPart.Position - target.PrimaryPart.Position).Magnitude
 end

I don’t get how you think this is even related to OOP, it’s saying that the target or instance parameter is nil.

1 Like

because it’s oop… if you can see it is

You’re not using object oriented programming how is it a problem???

do you actually know what oop is?

Do you know what a local function is?

1 Like

Luau Type Annotation (Type Checking) Error read this before you
actually think you know

The fact you wrote “oop” in capitals in the title suggests that you are mentioning object oriented programming.

1 Like

They are using OOP and you’re just using a local function??? You proved yourself wrong?

1 Like

This is not remotely related to OOP in Lua. Your problem is coming from the fact that when calling the function, one of your parameters are nil. Can you show us the code where the stack trace begins?

This is Luau’s type checking implementation. Luau type checking will not cause errors in your code (other than syntax errors)

Here’s a tutorial for you to touch up on the topic of OOP. Just please don’t make uneducated guesses and bash people for it.

3 Likes

you do notice oop can use that? function no matter if it say local?

This is hilarious… You haven’t even created a class. It’s OOP for a reason.

i actually did i just ain’t show my whole script you just don’t know what oop is for real… if you don’t know about it just say try ya best to fix

thank you for this i’ll look into it will help me fix my problem

Then OOP is irrelevant in this context. Don’t bite people for your mistakes.

:cup_with_straw::popcorn::grinning: Send all the code so we know what it is actually doing or at least where you call the function.

Are you sure the model has an PrimaryPart? That might be why it’s trying to index nil

instance.PrimaryPart has to be set for it to work.

1 Like

I figured it out it was this lol it wasn’t set