I don’t exactly know what you’re trying to do but it seems like you’re trying to implement a inventory system with a fixed resource limit. Heres how you can do this
local resourceLimit = 10
local data = {
['itzMehPlayin'] = {
{
Instance = resource; -- the resource object
Number = 10;
Location = location;
};
};
}
local resourceTemplate = {
Instance = nil; -- the resource object
Number = 0;
Location = location;
};
local function addResource(playerName: string, resource: Instance)
local resources = data[playerName] -- get the current resources
for _, resource in resources do
if resource.Instance.Name == resource.Name and resource.Number < resourceLimit then
resource.Number += 1 -- increment the resource by
return -- stop the function
end
end
local resource = table.clone(resourceTemplate) -- clone the template
resource.Number += 1 -- increment the resource by 1
table.insert(resources, resource) -- insert the resource to the player's resources data
end
addResource('itzMehPlayin', instance)
This is untested but it should work
I changed the resource layout because you can’t have 2 of the same keys
It’s just another style option, yes you can just use , if you wish to do so. And regarding the : it’s for type checking, for instance when you paste it in Roblox you’ll be able to see how when you call the function it’ll tell you more info.