I’ve never made an inventory system or a an equip system and i havbe not watched a tutorial I’m completely winging this with what I know so sorry if it’s abslloute cringe to look at, but this is what I’ve made.
This is on the client and basically when the button is clicked I save it to a variable and then if the player hits one of the equipment slots I kind of just do some checks and then I check on the server to make sure it’s all legit (if the player actually owns the item and the item slot matches with the slot it’s being equipped to)
button.MouseButton1Click:Connect(function()
local selected = button.Name --should be the name of the item
print(player.Name.." has selected "..button.Name)
for i,v in pairs(equipmentSlots:GetChildren()) do
v.MouseButton1Click:Connect(function()
print(player.Name.." has pressed "..v.Name)
if selected then --makes sure that an item is selected
local statsOfItem = getItemStats:InvokeServer(button.Name)
if statsOfItem.equipmentSlot == v.Name then --check to see if the items equipment slot data matches the slot name on the button
local successfullyEquipped = equip:InvokeServer(button.Name,v.Name) --server will check to make sure it's legit
if successfullyEquipped then
button:Destroy()
v.Text = button.Name
selected = nil
end
else
warn("tried to put item in the wrong slot")
end
else
warn("nothing selected")
end
end)
end
end)
And then this is on the server
equip.OnServerInvoke = function(player,itemToEquip,slotToEquipTo)
--print(itemToEquip,slotToEquipTo)
local inventory = playerManager:GetData(player,"inventory")
for i,v in pairs(inventory) do
if v == itemToEquip then --the player does in fact have the item inside their inventory
print("Check 1")
if items.stats[itemToEquip].equipmentSlot == slotToEquipTo then
print("Check 2")
for slot,currentlyEquipped in pairs(playerManager:GetData(player,"equipped")) do
if string.lower(slotToEquipTo) == slot and currentlyEquipped == "" then
print("equipping to: "..slot)
return true
end
end
else
return false
end
else
return false
end
end
end
It all seems to work however I’m trying to make sure it’s at least okay against exploiters and just if there’s any advice or tips to make this much better then that would help thanks
p.s: I keep making posts sorryyy been struglging a bit with doing some thinggs although I’ve managed to solve most of my previous questions lol