Fix to Nil Value

Hello! I am Domderp999. Scripter. I am currently experiencing nil values… When the value has a value and isnt in the wrong position… Pictures of the error:


The Code:

Any Possible fixes for this issue?

1 Like

the problem is the return for the function in the moduleScript called Module.new() is nil.

The Module :

yep - show me the entire function
(scroll down a bit )

the problem is that this function is a void (it doesn’t use the keyword return at all)

i dont know exactly how you want your code to run, but from the looks of it it seems like you want to add

return {FlareSize = FlareSize}

at the very end of the function.

1 Like

image
also in the picture above the flare value IS there… But it’s saying its nil. Im even getting the right position

that returns the ModuleScript data, - you still need one for the function

How So?

when you say

local Flr = LFM.new()

you are expecting LFM.new() to return something and make Flr equal to it, but you dont return anything.
By adding to the end of the function in the moduleScript:

return {FlareSize = FlareSize}

it will return what looks like the result you want, making your code work.

Like This?

Before your constructor function ends add something like:

return {
	Flare = newFlare,
	FlareSize = FlareSize,
	FlareFluct = FlareFluct
}

If NewFlare.new() returns a table like that then you can index “FlareSize” as if it were a “property” of the object.

For an OOP implementation the object’s constructor function has to return the newly created object.

Where do I put it? After this ?

nope, keep that script the same, dont change anything.
in the module script, the end of the function should look like this:

               v.ImageColor3 = Color
          end
     end
     return {
          FlareSize = FlareSize;
     }
end
1 Like

Thanks. I understand Now. Add me on discord you could most definitely help me in the future :eyes: Domderp999™#6273

You can return the newFlare instance itself since FlareSize and FlareFluct are already its children. Reconstructing the hierarchy seems redundant.

1 Like