How to make a shop system (trouble with equipped)

I’m making a shop, when you buy an item, it automatically equips it, but the previous item that was equipped stays equipped. How can I fix that?

I have a table for each item, and they have an key called “Equipped”, that is set to false, then to true when you equip it

1 Like

You clone the item into player backpack instead?

Do Humanoid:UnequipTools() before you equip

1 Like

How would I know which item was previously equipped, and set its Equipped boolean to false?

Don’t you just want to equip a new one? If so, it doesn’t matter which one was equipped before.

Humanoid:UnequipTools ()
Humanoid:EquipTool(ToolBought) -- your tool here

Like this

It actually does, in my shop there’s a text label for each item, that says whether the item is equipped or not

I tried using In Pairs but it did not work

for i, v in pairs(shopModule.gloves:GetChildren()) do
			
			if i["Equipped"] == true then
				
				i["Equipped"] = false
				
			end
			
		end

(probably because the keys aren’t its children)

Before you equip, just do Character: FindFirstChildOfClass(“Tool”).
That’s your equipped tool. Do it before you equip the new one. That’s your way to get the tool name/ the object itself

That’s not my problem ;-; the tool is the easy part, I’m talking about the boolean I have for each tool

shopModule.gloves = {
	
	["1"] = {
	
		["Price"] = 0;
		["Name"] = "No Gloves";
		["Owned"] = true;
		["Equipped"] = true;
	};
	
	["2"] = {
	
		["Price"] = 15;
		["Name"] = "Wooden Gloves";
		["Owned"] = false;
		["Equipped"] = false;
	};
	
	["3"] = {
	
		["Price"] = 50;
		["Name"] = "Stone Gloves";
		["Owned"] = false;
		["Equipped"] = false;
	};

How could I use In Pairs, to check if one of them has Equipped == true? (I tried to use GetChildren() on shopModule.gloves, but I guess that’s not how it works)

Just do:

And get the name. And in the shop module, loop through it, and if the name is equal, change it the equipped to false or the opposite
I am not sure, but here’s an example:

local tool = Character:FindFirstChildOfClass("Tool").Name
for i, v in ipairs(shopModule.gloves) do
      If(v["Name"] == tool) then
            v["Equipped"] = false
      end
end

Do that before you equip the new tool.

okay, imma change the Index to the name of the glove then

plr.Backpack:FindFirstChildOfClass("Tool").Name

could I do this?

1 Like

Yes, but don’t you want to check if it’s in the character? Because the character is the parent of the Equipped Tool

What do you mean when you say equipped? Does the player have only one tool? And it’s not in the character?
Only 1 item should be equipped in the shop?

You can only have one item equipped at a time

1 Like

You can do this then to find out which tool was equipped:

local tool = Backpack:FindFirstChildOfClass("Tool").Name
for i, v in ipairs(shopModule.gloves) do
      If(v["Name"] == tool) then
            v["Equipped"] = false
      end
end

Why dont you just save the tool equipped on the client only and update it with a remote event from the server?

Dang I forgot gloves was a table, I didn’t need to use GetChildren() ;-;

1 Like

Your current method of saving the tools seems inefficient