The items just act extremely weird when I try to click on them. Each slot of the inventory has this same code:
local TheValleyFunctions = require(workspace.ModuleScripts.TheValleyFunctions)
local Player = game.Players.LocalPlayer
local ClickedInventoySlot = require(Player.PlayerGui.ScreenGUI.Inventory.ClickedInventorySlot)
local UIS = game:GetService("UserInputService")
local Hitbox = script.Parent
local SlotFrame = Hitbox.Parent
local ItemImage = Hitbox.Parent.ItemImage
local SlotImage = Player.PlayerGui.ScreenGUI.ClickedSlot
local Item
local HitBox = script.Parent
local Slot = HitBox.Parent
local Inventory = Slot.Parent.Parent
local Tags = Slot.Tags
local function PlaceInSlot()
ItemImage.Image = SlotImage.Image
ItemImage.Counter.Text = SlotImage.Counter.Text
Slot.Count.Value = ClickedInventoySlot["Amount"]
Slot.ItemName.Value = ClickedInventoySlot["Item"]
Slot.Occupied.Value = true
end
local function ResetSelection()
SlotImage.Image = ""
SlotImage.Counter.Text = ""
end
local function Select(SlotInfo,Swap)
local Inventory = TheValleyFunctions.GetInventory(Player)
local SlotInformation
if Swap == true then
ClickedInventoySlot["Amount"] = Slot.Count.Value
ClickedInventoySlot["Item"] = Slot.ItemName.Value
else
ClickedInventoySlot["Amount"] = SlotInfo["Num"]
ClickedInventoySlot["Item"] = SlotInfo["Item"]
for i,v in Inventory.Data do
if tostring(i) == SlotFrame.Name then
SlotInformation = Inventory.Data[i]
for a,b in SlotInformation do
ClickedInventoySlot["Item"] = a
ClickedInventoySlot["Amount"] = b
print(ClickedInventoySlot)
end
end
end
end
print("Slot Information: ",SlotInformation)
local Position = UIS:GetMouseLocation()
local ImagePosition = UDim2.fromOffset(Position.X,Position.Y)
if Swap == false then
SlotImage.Image = ItemImage.Image
SlotImage.Counter.Text = ItemImage.Counter.Text
SlotImage.Position = ImagePosition
ItemImage.Image = ""
ItemImage.Counter.Text = ""
TheValleyFunctions.DeleteSlot(Player,tonumber(Slot.Name))
Slot.Occupied.Value = false
else
end
UIS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
local Position = UIS:GetMouseLocation()
local ImagePosition = UDim2.fromOffset(Position.X,Position.Y)
SlotImage.Position = ImagePosition
task.wait()
end
end)
end
script.Parent.MouseButton1Click:Connect(function()
print("Clicked Slot")
local SlotInfo = {
["Item"] = Slot.ItemName.Value,
["Num"] = Slot.Count.Value
}
if Slot.Occupied.Value == false then
print("Slot is not occupied")
if Inventory.ItemSelected.Value == true then
print("Item already selected")
TheValleyFunctions.ReplaceItem(Player,{
Num1 = ClickedInventoySlot["Amount"],
Item1 = ClickedInventoySlot["Item"],
SlotBeingReplaced = Slot.Name
})
PlaceInSlot()
ResetSelection()
Inventory.ItemSelected.Value = false
end
else
print("Slot occupied")
local InventoryTable = TheValleyFunctions.GetInventory(Player)
if InventoryTable.Data[tonumber(Slot.Name)][Slot.ItemName.Value] then
print("Item confirmed")
if Inventory.ItemSelected.Value == true then
print("Item already selected")
local NewSlotInfo = {
["Item"] = Slot.ItemName.Value,
["Num"] = Slot.Count.Value
}
TheValleyFunctions.ReplaceItem(Player,{
Num1 = ClickedInventoySlot["Amount"],
Item1 = ClickedInventoySlot["Item"],
SlotBeingReplaced = Slot.Name
})
Select(NewSlotInfo,true)
PlaceInSlot()
else
Inventory.ItemSelected.Value = true
print("Item not selected")
Select(SlotInfo,false)
end
end
end
end)
--script.Parent.MouseButton1Click:Connect(function(player)
--Inventory.SlotClicked:Fire(Slot,Tags)
--end)
The module script stores the information of what was clicked:
local ClickedInventorySlot = {
["Item"] = nil,
["Amount"] = nil
}
return ClickedInventorySlot