Hey! So I’m making an Inventory System, I followed the tutorial of DeadGambit and modified some stuff to my own liking! Surprisingly, it does work, equipping does work, putting new items into the inventory does work and so on! But I tried to make an unequip button using the tutorial of DeadGambit although his tutorial only had a script of deleting items in the player.Backpack with the same name as the item you’re trying to delete. What I’m trying to do is not that, I want it so it only deletes the ITEM that is the item I’m trying to delete instead of all the items with the same name. so I made some modification on the handle script and remote script I made from his tutorial. Simple Inventory System Part 2 | Handling Different Item Types(2021) - YouTube
You can see in his tutorial there’s a handler script thingy and that’s my LocalScript, there is also a remotes script in his tutorial which I followed and modified a little when I realized it deletes all the items with the same name as you’re trying to delete (UNEQUIP FROM BACKKPACK)
local plr = game:GetService("Players").LocalPlayer or game.Players.PlayerAdded:Wait()
local main = script.Parent.Parent.Parent.InventoryFrame
local replicated = game:GetService("ReplicatedStorage")
local remotes = replicated.RemoteEvents
local inventoryremotes = remotes.Inventory
local cooldown = false
for index, child in pairs(script.Parent:GetChildren()) do
if child:IsA("TextButton") then
child.MouseButton1Click:Connect(function()
if child.Name == "Equip" then
if child.Text == "Equip" then
for index, items in pairs(main:GetChildren()) do
if items:IsA("ImageButton") and cooldown == false then
if script.Parent.ItemDisplayed.Value == items and items.Equipped.Value == false then
items.Equipped.Value = true
inventoryremotes.EquipItem:FireServer(items.name, items.Tool.Value, "Equipped")
print("Activated Remote 1")
child.Text = "Unequip"
cooldown = true
wait(1)
cooldown = false
end
end
end
elseif child.Text == "Unequip" then
for index, items in pairs(main:GetChildren()) do
if items:IsA("ImageButton") and cooldown == false then
if script.Parent.ItemDisplayed.Value == items and items.Equipped.Value == true then
items.Equipped.Value = false
inventoryremotes.EquipItem:FireServer(items.name, items.Tool.Value, "Unequipped")
print("Activated Remote 2")
child.Text = "Equip"
cooldown = true
wait(1)
cooldown = false
end
end
end
end
end
end)
end
end
As you can see, I went through alot of tables, I have an object value in my ImageButton for the Item and I wanted that objectvalue’s value to be the Tool that was cloned in the player backpack.
Here’s my remote script:
local plr = game:GetService("Players").LocalPlayer or game.Players.PlayerAdded:Wait()
local replicated = game:GetService("ReplicatedStorage")
local remotes = replicated.RemoteEvents
local inventoryremotes = remotes.Inventory
local backpack = plr
inventoryremotes.EquipItem.OnServerEvent:Connect(function(plr, item, object, condition)
if condition == "Equipped" then
local selecteditem = replicated.Fruits.Fruit[item]:Clone()
selecteditem.Parent = plr.Backpack
object = selecteditem
print("equipped that sheesh")
elseif condition == "Unequipped" then
for index, equippedItems in pairs(plr.Backpack:GetChildren()) do
if equippedItems.Name == item then
if object == equippedItems then
local deleteitem = plr.Backpack[item]
deleteitem:Destroy()
object = nil
end
end
print("Destroyed that sheesh")
end
end
end)