Why is my class instance nil?
Asked by
4 years ago Edited 4 years ago
OOP HELP... I have created my own class Point
and I have 2 simple methods in it Point:print()
and Point:getMagnitude()
. Here is code:
01 | local Class = require(game.ReplicatedStorage.Class) |
03 | local Point = Class:extend() |
05 | function Point:new(x,y,z) |
12 | print (self.X,self.Y,self.Z) |
15 | function Point:getMagnitude() |
16 | return math.sqrt(self.X^ 2 +self.Y^ 2 +self.Z^ 2 ) |
My problem is when I run some server code that tests the class I get this error: ReplicatedStorage.Point:12: attempt to index nil with 'X'
I don't see any typos, and I do have a constructor method that should give me self
... Help me! :(
Server Code:
1 | local Point = require(game.ReplicatedStorage.Point) |
2 | local pointA = Point( 3 , 4 , 5 ) |
4 | local pointAMag = pointA:getMagnitude() |
Summary: self is nil when it should not be...
Line 1 Documentation: https://github.com/rxi/classic