What’s the best way to store models?

GuiService | Roblox Creator Documentation this shows how to set the message for the text button

this is the same thing only for the image button → ImageButton | Roblox Creator Documentation

There are a few ways I can think of to achieve this.

Do you already have a way of detecting when a cosmetic is added to the inventory?

At the moment I do not have a way of detecting when a cosmetic is added to an inventory. All I know right now I can have tables to store all the info then clone that table to an inventory table. What I don’t know how to do is have the info be translated to gui.

You can send that info to the server or client.

Here is one example:

– ModuleScript (located in ServerScriptService)

local module = {}

module.CosmeticInfo = {
["Fire Sword"] = {
Name = "Fire Sword";
Type = "Sword";
ImageId = 12345678;
Rarity = "Legendary";
RarityGlowImageId = "IMAGE_ID_HERE";
Price = 1234;
};
[""] = {};
}

Now, the server will detect and give the player a new cosmetic.

– Server

-- giving a new cosmetic
local ModuleScript = require(game:GetService("ServerScriptService").ModuleScript)
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent -- this will allow us to communicate with the client


function GiveCosmetic(player_instance, cosmetic_name)
  if (ModuleScript.CosmeticInfo[cosmetic_name] ~= nil) then
   local Information = ModuleScript.CosmeticInfo[cosmetic_name]
   local Cosmetics = game:GetService("ServerStorage").Cosmetics -- Folder with cosmetics 
    
    local Item = Cosmetics:WaitForChild(cosmetic_name) or nil -- get the cosmetic 
    if (Item ~= nil) then
    Item:Clone().Parent = INVENTORY -- send the cosmetic to the player's inventory
    RemoteEvent:FireClient(player_instance, Information) -- This will send data of the new item to the client
    end
   
  end
end

– Client (LocalScript)

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

RemoteEvent.OnClientEvent:Connect(function(...)
print(...)
-- You could send this information to a ModuleScript that sorts it out ClientModule.UpdateGUI(...)

local Info = ...
print(Info["Name"], Info["Price"])
end)

This is just an example of how I’d do it, there are other ways and maybe even better ways. I am still learning myself but I hope this was helpful. Let me know if you have any questions!

1 Like

This helped a lot actually with explaining the process! What I’m mostly wondering is how to make the info translate to gui specifically. So say in a table for a cosmetic the rarity = epic. Then when that is cloned to the inventory via to process you mentioned, how do I make it so it sees that the rarity is epic and adds the corresponding rarity glow to the inventory box for the cosmetic

Let’s say you have a ModuleScript that handles updating the GUI.

local module = {}
local Player = game.Players.LocalPlayer

module.UpdateGUI = function(ItemInfo) -- ItemInfo is the info we received from the server's modulescript
local Gui = Player:WaitForChild("PlayerGui").InventoryGUI
local Template = script:WaitForChild("Frame"):Clone() -- We have a Frame that we will add to the GUI (Frame with Name, Rarity, Price...)

-- Update the Frame's info
Template.Name.Text = ItemInfo["Name"] -- Fire Sword
Template.Rarity.Text = ItemInfo["Rarity"] -- Legendary
Template.RarityGlow.Image = ItemInfo["RarityGlowImageId"] -- Legendary
-- continue for the rest...


Template.Parent = Gui -- Now after we have finished setting up the frame, we place it into the Inventory Gui
end
1 Like

OMG THATS EXACTLY WHAT I WAS WANTING TO KNOW. So pretty much I make a template box then when a cosmetic is purchased and then cloned from the main module script storing all the info I clone the template box and then it changes the stuff such as name, rarity, etc to match the info in the table for that cosmetic?

I just updated it to add the RarityGlow, glad I could help!

Yes, have a default template box. Then, when the cosmetic is purchased clone and set it up.

Client purchases cosmetic

Server gives cosmetic and sends the cosmetic info to client via RemoteEvent

Client takes the info sent from server and makes a new box to add to the inventory gui
1 Like

I’ll probably have the rarity glow be an image id too. So would pretty much set up a series of elseif statements?

If rarity = Legendary then
Template.RarityGlow = (Image ID of Legendary Glow)
elseif rarity = Epic then
Template.Rarity Glow = (Image ID of Epic Glow)
—and so on—

Yep.

if (Rarity == "Legendary") then
return "image id"
end

Or you could have the image id set in the modulescript with the rest of the info.

1 Like

Awesome! So do I also set the new rarity glow in the section where we update the frame’s info?

Yes

1 Like
module.UpdateGUI = function(ItemInfo) -- ItemInfo is the info we received from the server's modulescript
local Gui = Player:WaitForChild("PlayerGui").InventoryGUI
local Template = script:WaitForChild("Frame"):Clone() -- We have a Frame that we will add to the GUI (Frame with Name, Rarity, Price...)

-- Update the Frame's info
Template.Name.Text = ItemInfo["Name"] -- Fire Sword
Template.Rarity.Text = ItemInfo["Rarity"] -- Legendary
Template.RarityGlow.Image = ItemInfo["RarityGlowImageId"] -- Legendary

-- continue for the rest...


Template.Parent = Gui -- Now after we have finished setting up the frame, we place it into the Inventory Gui
end

This would be a better way of doing it, have the image id with the rest of the info

1 Like

Thank you so so so much for all of this dude! This was my biggest challenge when figuring out how to make an inventory system. There’s plenty of tutorials on how to make an inventory system on Roblox. But I also have a shop system in the game I’m making and all the tutorials for both were making me create a bunch of tables to store stuff. Then @betterthenharrybarry explained that I can store the info via a module script & tables, so that eliminated problem 1. Problem 2 was how to make stuff for cosmetics appear in the inventory, solution is cloning. Problem 3 was making that info appear via gui, you solved that problem exactly how I was needing to! Thank you so much for the help!

1 Like

@Prince_Duke I have a question. So for Datastores I was thinking of just using massive table systems. So ofc we have the module script storing the tables of info and whatnot for cloning right? So when a player buys a cosmetic it clones it then does the inventory thing you told me about. To save player’s inventory data I want to make it so any cosmetic cloned to the inventory is put on a table. How would I implement this, any suggestions?

I’m reviving this because I need help with execution. How to make an inventory and shop system
@betterthenharrybarry @Prince_Duke

what do you mean you need help with execution?

Duke helped massively with figuring it out and now I kinda know what to do. Player buys skin, the table for that skin and the model are cloned from rep storage into an inventory table & folder then saved. Then when a new skin is added or a player first loads into the game it creates a slot for each skin, checks the name, finds the table with that name, reads it’s info, and changes the template to show that info. Then when a player leaves it saves the inventory table and folder then uses it to load the player’s info when they rejoin. On top of that each weapon type has a category/tab in the inventory, so I gotta set that up too somehow. I know what to do and partially how to code it, I just need help figuring out how to code the other 75% lol.

Although i think i might understand what you are saying i might not but here is some roblox creator documentations to help you sort it out.

DataStore | Roblox Creator Documentation
Tables | Roblox Creator Documentation

another thing i also recommend you do to get better at coding is either 1 look up the problem or 2 just try and find the problem yourself to see if you made a slight mistake maybe as that is what normally happens sometimes in the devforum. i also recommend going to the developer documentation s it normally gives you some decent info that isnt outdated on the objects you can use, unlike a regular youtube video you can search up.

1 Like

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