Custom function in custom datatype (SOLVED)

I did post this because I wanted to know how to set a function in a custom datatype.
For example

local Region4 = {}
type RegionObject = {
	PlayerTouched : RBXScriptSignal,
	Touched : RBXScriptSignal,
	TouchEnded : RBXScriptSignal,
	PlayerTouchEnded : RBXScriptSignal
}

function Region4.new(Size:Vector3, cf:CFrame, CanCollide:boolean?) : RegionObject
end

function Region4:ConvertPartToRegion(part:BasePart) : RegionObject
end

return Region4

I have “type RegionObject” in my script, and I defined some events in it.
But I couldn’t know how to define functions inside a custom datatype.
Can someone please tell how should i define a function in my custom datatype?

I want something like :

type custom_type = {
    -- functions defined ( assume that function defined is "Func"
}

function example() : custom_type
end

example():Func()

and,
DevforumPicutre
I want the function to show like the picture above when using a value that is the custom type
plz help :disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved::sob::disappointed_relieved::scream::face_holding_back_tears::astonished::face_holding_back_tears::face_holding_back_tears::astonished::face_with_monocle::worried::astonished::face_holding_back_tears::astonished::scream::astonished::face_holding_back_tears::worried::face_with_monocle::face_holding_back_tears::astonished::scream:

( ask me questions if you cant understand, im bad at explaining something like this )

You could either just use a metatable (in which case functions will get automatically detected by the inference engine), or explicitly type it by doing something like:

export type Region4 = {
  GetPartsInRegion: () -> ({BasePart}?)
}

The first parentheses contains any input arguments and the second one has whatever it returns

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.