Roblox Studio does it’s best autocompleting tables and stuff but sometimes it doesn’t know like in this example.
local PlayerProfiles = {}
PlayerProfiles.__index = PlayerProfiles
function PlayerProfiles.GetProfile(player)
return PlayerProfiles[player]
end
function PlayerProfiles:AddBitcoin()
end
game.Players.PlayerAdded:Connect(function(player)
PlayerProfiles[player] = setmetatable({}, PlayerProfiles)
end)
return PlayerProfiles
As you can see here there are no suggestions:
And here there are suggestions:
Even though they are the same object.
Is there a way to help guide the autocomplete by explicitly telling it the return type? I know you can do
function PlayerProfiles.GetProfile(player): {}
return PlayerProfiles[player]
end
but all this says is that it returns a table and not which specific table.
Thank You! This is exactly what I was looking for!
I always thought it was weird to do the first method you showed because then I would have to keep the profile type in sync with the profile object in order for it to be accurate. Almost like there were two sources of truth instead of one.