Type of table defined but after returning table it doesn't autofill in other script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve a defined table with a Value and a Changed value that is returned from a method and can autofill when typing the Value or the Changed value without having to define the table and its values in the other script.

  2. What is the issue? Include screenshots / videos if possible!
    It doesn’t autofill when I try to type Value or Changed
    Desired result:
    image
    Result I get:
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried defining the type in many different ways, but every time it doesn’t autofill, except when I define the type in another script like this:
    image
    which is not what I want, I want it to be returned and instantly autofill without getting the type from another script.

I have tried looking for solutions but none of them worked.

It works perfectly, just no autofill.

My code:

export type datatype = {
	Value: any,
	Changed: RBXScriptSignal,
}

function playermetatable:AddData(DataName:string,Value:any,LoadData: boolean) : datatype?
	local success,result = xpcall(function()
		local_funcs.DebugPrint(`Adding data for user {self.Name} DataName:{DataName} Value:{Value} LoadData? {LoadData}.`,print)
		local data:table = self.Data
		data[DataName] = {}
		local newData = data[DataName]
		local valuename = "Value"
		if LoadData and LoadData==true then
			local datatoset = local_funcs.LoadDataForNewValue(self,DataName)
			if datatoset and datatoset[valuename] then
				newData[valuename] = datatoset[valuename]
			else
				newData[valuename] = Value
			end
		else
			newData[valuename] = Value
		end
		local_funcs.DebugPrint(`Data successfully added for {self.Name}.`,print)
		newData.Changed = signal().new()
		data[DataName] = newData
		setmetatable(data[DataName],valuefuncs)
		newData = nil
		print(data[DataName])
		return data[DataName]
	end,function()
		return `Failed to add data for {self.Name}`
	end)
	if success then
		return result
	else
		warn(result)
		return nil
	end
end

Edit: After a bit more testing, it seems that it has to do something with the metatable I use, a normal function or method returns the table and the autofill works, is there a way I could make this work with the metatable though?

Works for me.


Weird, it works when I try a normal metatable but for some reason in this script, it doesn’t work. I have no clue what the issue could be however.