Hello. I currently need help on how to equip and unequip accessories. I will explain the sorting part later.
First: I have the buying of the accessory all worked out but how do I make a seperate Equip and Unequip function? I tried to code a equip button and it added the accessory to the humanoid but the character is not shown to be wearing it. So from scratch, how do I make a Equip and Unequip button?
Second: Sorting the accessories,
Now, i’m trying to wrap my head around this one but I can’t seem to figure it out. What I am trying to do is when a player buys lets say a Hat, it gets added (and sorted if there are multiple accessories the player bought) to the player’s inventory and then the player can equip it. How do I do this?
An inventory GUI will not work. It is used for tools and items in the starter pack. I am doing accessories here. I did exactly what you said (the code) and it didn’t work. (Previous I was already using it as explained in the post)
Oh, well in the title it says “sorting them in a GUI” so I assumed you were making an inventory gui. No, you cannot easily sort a players inventory without placing them in order manually.
To equip an accessory, the accessory needs to be located in the character. Just put the accessory in the character and it will automatically be put in place (If its a roblox catalog item).
I’m sorry. I think I have not made it clear. I made the GUI where you can buy the hat. When you buy it, it creates an accessory in the character. But it does not show up on their character. Then I want the player to have the option to unequip the item.
About the sorting, when the player buys a hat, I want the script to detect that the hat was bought and add it to the inventory. (This is my own GUI inventory. Not roblox’s)
You will want to create an inventory gui that shows what hats they have. You should store what hats they have in a datastore and when the player presses to equip the hat.
Below is a quote from a forum that might help you add the hats. (I took out stuff you wont need.)
Yeah. How do I make the inventory GUI exactly? Just need some brief explanations. When a player buys the hat, it will be added to their inventory and they can equip it from there. How can I do that? Maybe some pseudo code will help! Thank you!
DSS = game:GetService("Datastore Service")
-- this wont work as is, you need to sort out the datastores.
local HatNames = ""
for i = 1,#HatInventory do
HatNames = HatNames .. HatInventory[i].Name .. ";"
end
DSS:SetAsync(tostring(PlayerId),HatNames)
local HatList = {}
local Hats = DSS:GetAsync(tostring(PlayerId))
local Split = string.split(Hats,";")
for i = 1,#Split do
if Split[i] == "HatName" then
table.insert(HatList,Split[i])
-- Make hat in thier inventory.
end
end