Hey y’all, so I’ve been working on an inventory system for the past few days and have ran into an issue that I don’t know how to fix. For some context, my inventory system has different categories named “Pockets” to better sort and organize the player’s items. The intended behavior is that items from one category, let’s say Medicine for example, are only visible in the Medicine pocket and not the Discs pocket. But as my script currently works, the items continue persist and appear in other pockets instead of disappearing. So now potions end up appearing in the discs pocket, and vice versa. Any help figuring out a solution to this problem will be greatly appreciated!
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local PlayerGui = player.PlayerGui
local globalVariables = require(ReplicatedStorage.Modules.globalVariables)
local movesData = require(ReplicatedStorage.Modules.Data.BattleData.movesData)
local experienceData = require(ReplicatedStorage.Modules.Data.BattleData.experienceData)
local personalitiesData = require(ReplicatedStorage.Modules.Data.BattleData.personalitiesData)
local itemsData = require(ReplicatedStorage.Modules.Data.itemsData)
local mathModule = require(ReplicatedStorage.Modules.Services.MathService.mathModule)
local gatchipediaModule = require(ReplicatedStorage.Modules.Services.GatchipediaService.gatchipediaModule)
local battleModule = require(ReplicatedStorage.Modules.Services.BattleService.battleModule)
local buttonActions = require(game.StarterPlayer.StarterCharacterScripts.Character.buttonActions)
local getInventoryFunction = ReplicatedStorage.remoteFunctions.getInventory
local playerItems = getInventoryFunction:InvokeServer()
local GUI = PlayerGui.Main.GUI
local Bag = GUI.Bag
local InventoryScroll = GUI.Bag.InventoryScroll
local ItemSlot = PlayerGui.Templates.ItemSlot
--scroll text function here
function hash(num)
return (num + 4) * 8
end
function dehash(num)
return (num - 32) / 8
end
function HPCalculation(level, up, tp, gatchi)
return(up + 2 * globalVariables.Gatchimon[gatchi].Stats.HP + tp / 4) * 100 + 10 + level
end
function otherStatCalculation(basestat, level, up, tp, personality, gatchi)
return((up + 2 * globalVariables.Gatchimon[gatchi].Stats[basestat] + tp / 4) * level / 100 + 5) * personality
end
local stats = { "HP", "STA", "ATK", "DEF", "MA", "SPD" }
function determinePersonality(stat, personality)
if personalitiesData[stat .. "Up"][personality] then
return 1.1
elseif personalitiesData[stat .. "Down"][personality] then
return 0.9
else
return 1
end
end
--Initalize the inventory
local currentPocket = "Medicine"
local function loadItems()
for itemName, itemData in pairs (itemsData) do
local newItem = ItemSlot:Clone()
if itemData.Class == "Medicine" and currentPocket == "Medicine" then
newItem.Visible = false
newItem.Parent = InventoryScroll
newItem.NameButton.Text = itemData.DisplayName
newItem.ItemIcon.Image = itemData.Image
newItem:AddTag(itemData.Class)
newItem.ItemIcon:AddTag(itemData.Class)
buttonActions.invItem(newItem.NameButton)
elseif itemData.Class == "Item" and currentPocket == "Items" then
newItem.Visible = false
newItem.Parent = InventoryScroll
newItem.NameButton.Text = itemData.DisplayName
newItem.ItemIcon.Image = itemData.Image
newItem:AddTag(itemData.Class)
newItem.ItemIcon:AddTag(itemData.Class)
buttonActions.invItem(newItem.NameButton)
elseif itemData.Class == "CaptureDisc" and currentPocket == "Discs" then
newItem.Visible = false
newItem.Parent = InventoryScroll
newItem.NameButton.Text = itemData.DisplayName
newItem.ItemIcon.Image = itemData.Image
newItem:AddTag(itemData.Class)
newItem.ItemIcon:AddTag(itemData.Class)
buttonActions.invItem(newItem.NameButton)
elseif itemData.Class == "MoveManual" and currentPocket == "Move Manuals" then
newItem.Visible = false
newItem.Parent = InventoryScroll
newItem.NameButton.Text = itemData.DisplayName
newItem.ItemIcon.Image = itemData.Image
newItem:AddTag(itemData.Class)
newItem.ItemIcon:AddTag(itemData.Class)
buttonActions.invItem(newItem.NameButton)
elseif itemData.Class == "Fruit" and currentPocket == "Fruits" then
newItem.Visible = false
newItem.Parent = InventoryScroll
newItem.NameButton.Text = itemData.DisplayName
newItem.ItemIcon.Image = itemData.Image
newItem:AddTag(itemData.Class)
newItem.ItemIcon:AddTag(itemData.Class)
buttonActions.invItem(newItem.NameButton)
elseif itemData.Class == "Key" and currentPocket == "Key Items" then
newItem.Visible = false
newItem.Parent = InventoryScroll
newItem.NameButton.Text = itemData.DisplayName
newItem.ItemIcon.Image = itemData.Image
newItem:AddTag(itemData.Class)
newItem.ItemIcon:AddTag(itemData.Class)
buttonActions.invItem(newItem.NameButton)
end
newItem.Name = itemName
end
end
--Change pockets
local function changePocket(Pocket: "Medicine" | "Items" | "Discs" | "Move Manuals" | "Fruits" | "Key Items")
currentPocket = Pocket
loadItems()
--Load the player's items
if playerItems ~= nil then
for itemName, itemData in pairs (playerItems) do
if itemData.uses > 0 then
local item = InventoryScroll:FindFirstChild(itemName)
if not item then continue end
item.Visible = true
item.UsesLabel.Text = "x" .. itemData.uses
end
end
end
end
--Item functions
function Heal(item, gatchimon, Recover)
if gatchimon.currentHP.Value == gatchimon.Stats.HPStat.Value or gatchimon.Status.Value == "Faint" then
loadItems()
else
mathModule.Change(gatchimon.currentHP, math.min(gatchimon.currentHP.Value + item.Use.Heal, gatchimon.Stats.HPStat.Value))
mathModule.Check(Recover[item], false)
end
loadItems()
end
function FullRestore(item, gatchimon, Recover)
end
function CureStatus(item, gatchimon)
end
function CuresAll(item, gatchimon)
end
function RaiseStat(item, gatchimon)
end
function Exp(item, gatchimon)
end
function Catch(item, gatchimon)
local bonusStatus = 1
if gatchimon.Status.Value == "Paralysis" or gatchimon.Status.Value == "Drowsy" then
bonusStatus = 2
else
if gatchimon.Status.Value == "Burn" or gatchimon.Status.Value == "Frostbite" or gatchimon.Status.Value == "Poison" then
bonusStatus = 1.5
end
end
mathModule.Check(player.Bag.CaptureDisc[item])
local HPMax = gatchimon.Stats.HPStat.Value
local HPCurrent = gatchimon.currentHP.Value
local rate = 1
--put other capture discs here
--end
local catchRate = math.min(100, math.max(0, math.floor(HPMax * rate * bonusStatus / 3 / HPCurrent)))
local shakeChecking = 65536 / 255 / catchRate ^ 0.25
local shakeCheck = nil
local shakes = 0
for i = 1, 3 do
local shakeWeight = math.random(0, 65535)
if catchRate > 255 or item == "Ultimate Disc" then
shakes = 3
shakeCheck = "Success"
break
elseif shakeChecking < shakeWeight then
shakeCheck = "Fail"
break
elseif shakes == 3 then
shakeCheck = "Success"
else
shakes = shakes + 1
end
end
end
function Evolve(item, gatchimon)
end
function RaiseLevel(item, gatchimon)
--soundEffect here
if gatchimon.Level.Value < 100 and gatchimon.currentHP.Value > 0 then
--soundEffect:Play()
mathModule.Change(gatchimon.Experience, hash(experienceData[gatchimon[gatchimon.Name].GrowthRate .. "EXP"](gatchimon.level.Value)))
local HPBefore = gatchimon.Stats.HPStat.Value
for i, v in ipairs(stats) do
if v == "HP" then
--mathModule.Change(gatchimon.Stat[???], ???(gatchimon.Level.Value, gatchimon.UP[???].Value, ???, ???))
else
--mathModule.Change(gatchimon.Stat[???], ???(gatchimon.Level.Value, gatchimon.UP[???].Value, ???, ???))
end
end
mathModule.Change(gatchimon.currentHP, gatchimon.currentHP.Value + (gatchimon.Stats.HPStat.Value - HPBefore))
if gatchimon.currentHP.Value == 0 then
gatchimon.Status.Value = "Faint"
end
--check if the gatchimon can evolve
end
end
--Buttons
local MedicineButton = GUI.Bag.MedicineButton
local ItemsButton = GUI.Bag.ItemsButton
local DiscsButton = GUI.Bag.DiscsButton
local MMsButton = GUI.Bag.MMsButton
local FruitsButton = GUI.Bag.FruitsButton
local KeyButton = GUI.Bag.KeyButton
local CloseButton = GUI.Bag.CloseButton
MedicineButton.Activated:Connect(function()
changePocket("Medicine")
print("Changed pocket to Medicine!")
end)
ItemsButton.Activated:Connect(function()
changePocket("Items")
print("Changed pocket to Items!")
end)
DiscsButton.Activated:Connect(function()
changePocket("Discs")
print("Changed pocket to Discs!")
end)
MMsButton.Activated:Connect(function()
changePocket("Move Manuals")
print("Changed pocket to Move Manuals!")
end)
FruitsButton.Activated:Connect(function()
changePocket("Fruits")
print("Changed pocket to Fruits!")
end)
KeyButton.Activated:Connect(function()
changePocket("Key Items")
print("Changed pocket to Key Items!")
end)```
