something like this
local [game.InsertService:LoadAsset(AdorneeId).Name] = NewTable
How could i make a variable with the name of the asset being loaded? for that i would need the string generated by the name property but it does not work.
something like this
local [game.InsertService:LoadAsset(AdorneeId).Name] = NewTable
How could i make a variable with the name of the asset being loaded? for that i would need the string generated by the name property but it does not work.
why not just use a table
local Table = {}
Table[game.InsertService:LoadAsset(AdorneeId).Name] = NewTable
Because that complicates things unnecessarily.
also because [game.InsertService:LoadAsset(AdorneeId).Name]
does not work
I mean I don’t see how a table complicates things
Variables cannot be generated like how you’re asking for it to be. It’s not “meant” to be created like that.
I suggest rethinking the way you’re handling the naming, since it’s restrictive towards the name of whatever you’re fetching (your system should already know what its name is beforehand), as well as unprotected if LoadAsset ever returns nil (which is will from time to time).
so i can’t get a string value from name to then set as the name for a variable?
Pretty much yeah.
You should avoid using the names of the models as identifiers anyway, since multiple models can have the same name while their assetID is unique to that model. I would suggest using the ID as your basis to identify the model, and then use a table like D0RYU mentioned to cache your models. This way you could potentially do something like:
local model = tableOfModels[assetID]
…and it should exist if assigned properly. It’s not complicating anything since it’s just a cache reference, which is something you’re already trying to achieve.
Also, one more thing, doe :LoadAsset just fail randomly at times or is it a loading thing that has to be waited out?
Pretty sure it’s not that it returns nil, but it errors if it fails to fetch the model. So you’ll want to wrap the function in a pcall, and then if the pcall was unsuccessful you’d repeat the process until it eventually does go through (depending on your application).