I need help with my custom datatype

it is saying: attempt to index nil With ‘Y’.
because i only said defoned the datatype and not the thing itself
but what i can do? i want it to print “MyType”
what should i define it as?





type MyType = {
	Y: number,
	X: number,
	YD: number,
	XD: number,
	
}


local MyType = {}

function MyType.new(Y,X,YD,XD): MyType
	local New: MyType
	New = New
	New.Y = Y
	New.X = X
	New.YD = YD
	New.XD = X
	
	return New
end

local d = MyType.new(1,3,4,5)

print(typeof(d))











1 Like

You are not able to change the value of typeof afaik, it will always be table for tables.

You are also assigning New to New which is nil, you should assign it to a table instead.

Question: will it return a table when i use typeof?

It will return the string "table" as MyType.new() returns a table

no. did not work. the output said “table”.
@Luka_Gaming07

function MyType.new(Y,X,YD,XD): MyType
	local New : MyType = {}
	New.Y = Y
	New.X = X
	New.YD = YD
	New.XD = X
	
	return New
end

This is what you shud do. The typechecking was a little bit off.

no. that did not work; it even gave me a warning

Are you trying to create a class like vector3?

i just wanted to test how creating a custom type works.

But yeah, Vector2,Vector3, Udim,Udim2

Pretty sure those datatypes are just classes(built in by roblox)

hmmmm so you can’t actually just make it so that when you call:

typeof(idk anything) – returns custom type?

if it was true, then wouldnt be
table.concat the only existing solution or the way out of the problem?

I think typeof is roblox’s custom function for datatypes including its built in ones. So I don’t think it would detect your custom datatypes.

K i just realized that ur variable overshadowing, i.e u r declaring MyType as a type and as a table . So it might automatically set the type as a table .

that did not help att all.

Vector3.

Udim2

Y, X, YScale …

I don’t understand what you’re saying?

can you tell me something else cause…
MyType i dont think it will be a table or

imagine doing

type MyType = (Y:number,X:Nmber --.. and so on

It has to be a table ??? Vector3 and Udmi2 are classes that have functions that return a table. You the .new function using () and pass arguments.

:man_facepalming:t4:
that is not what i mean.
if you do:

typeof(Vector3)
returns Vector3 and NOT “table”

also, one more thing…

if i had to do what you’re saying then the output will return:
[“Y”] = 1,
And so on…

but i want to say insteaad : 1,3,4,5