hi, so I have used a community resource (Custom Inventory System: Full tutorial + Model - #11 by Fantasiuss) and made it a 6 slots limited inventory, however the problem comes when you would like to drop an item by dragging it out of the inventory. The item disappears however the icon stays.
Adding a print below the line thats supposed to reset the image prints on the output so the script does go thru the line but i guess there is something wrong with it
below is the part of the code that is the issue. I tried setting the .Image to “”; " "; 0; it just simply ignores the line of code which trys to change .Image of item slot. And as I spend already a decent amount of time on it I finally decided to ask for help.
local originalSlot = hotbar:FindFirstChild("SLOT" .. tostring(currentItemSelected.slotIn.Value))
if originalSlot then
originalSlot.itemImage.Image = ""
originalSlot.UIStroke.Color = Color3.fromRGB(20, 20, 20)
end
game.ReplicatedStorage:WaitForChild("Events").DropToolEvent:FireServer(currentItemSelected, currentItemSelected.Handle.Position)
Full module for context down below
local module = {}
local UIS = game:GetService("UserInputService")
local slotsToNums = {
["SLOT1"] = 1,
["SLOT2"] = 2,
["SLOT3"] = 3,
["SLOT4"] = 4,
["SLOT5"] = 5,
["SLOT6"] = 6,
}
local currentFrameBeingHoveredOn = nil
local currentItemSelected = nil
local isDraggingItem = false
function module.HoverFrameChange(toggle, frame)
currentFrameBeingHoveredOn = toggle and frame or nil
end
function module.HotbarLoad(hotbar, backpack)
for _, item in pairs(backpack:GetChildren()) do
if item:IsA("Tool") then
-- Automatically assign to a slot if slotIn.Value is 0
if item.slotIn.Value == 0 then
for i = 1, 6 do
local slot = hotbar:FindFirstChild("SLOT" .. tostring(i))
if slot and slot.itemImage.Image == "" then
item.slotIn.Value = i
slot.itemImage.Image = item.TextureId
break
end
end
else
local slot = hotbar:FindFirstChild("SLOT" .. tostring(item.slotIn.Value))
if slot then
slot.itemImage.Image = item.TextureId
end
end
end
end
end
function module.MouseDown(currentMousePos, slotDragger, backpack, bag, hotbar, itemTemplate)
if not isDraggingItem and currentFrameBeingHoveredOn then
if currentFrameBeingHoveredOn:IsDescendantOf(hotbar) then
for _, item in pairs(backpack:GetChildren()) do
if item:IsA("Tool") and item.slotIn.Value == slotsToNums[currentFrameBeingHoveredOn.Name] then
currentItemSelected = item
break
else
currentItemSelected = nil
end
end
if currentItemSelected then
isDraggingItem = true
slotDragger.itemImage.Image = currentFrameBeingHoveredOn.itemImage.Image
slotDragger.Visible = true
currentFrameBeingHoveredOn.itemImage.Image = ""
while isDraggingItem do
currentMousePos = UIS:GetMouseLocation()
slotDragger.Position = UDim2.fromOffset(currentMousePos.X, currentMousePos.Y)
task.wait()
end
end
end
end
end
function module.MouseUp(slotDragger, hotbar, bag, backpack, itemTemplate)
isDraggingItem = false
if currentItemSelected then
if not currentFrameBeingHoveredOn or not currentFrameBeingHoveredOn:IsDescendantOf(hotbar) then
local originalSlot = hotbar:FindFirstChild("SLOT" .. tostring(currentItemSelected.slotIn.Value))
if originalSlot then
originalSlot.itemImage.Image = ""
originalSlot.UIStroke.Color = Color3.fromRGB(20, 20, 20)
end
game.ReplicatedStorage:WaitForChild("Events").DropToolEvent:FireServer(currentItemSelected, currentItemSelected.Handle.Position)
else
for _, otherItem in pairs(backpack:GetChildren()) do
if otherItem:IsA("Tool") and otherItem ~= currentItemSelected and otherItem.slotIn.Value == slotsToNums[currentFrameBeingHoveredOn.Name] then
if currentItemSelected.slotIn.Value == 0 and otherItem.slotIn.Value ~= 0 then
hotbar:FindFirstChild("SLOT" .. tostring(otherItem.slotIn.Value)).itemImage.Image = ""
end
otherItem.slotIn.Value = currentItemSelected.slotIn.Value
end
end
currentItemSelected.slotIn.Value = slotsToNums[currentFrameBeingHoveredOn.Name]
end
end
module.HotbarLoad(hotbar, backpack)
slotDragger.Visible = false
currentItemSelected = nil
currentFrameBeingHoveredOn = nil
end
function module.ItemEquip(item, hum, hotbar)
hum:EquipTool(item)
local slot = hotbar:FindFirstChild("SLOT" .. tostring(item.slotIn.Value))
if slot then
slot.UIStroke.Color = Color3.fromRGB(255, 255, 255)
end
end
function module.ItemUnequip(hum, hotbar)
hum:UnequipTools()
for _, slot in pairs(hotbar:GetChildren()) do
if slot:IsA("Frame") then
slot.UIStroke.Color = Color3.fromRGB(20, 20, 20)
end
end
end
return module