Soo after i made first snapshot, i moved slots in my inventory around for a few minutes, then when i made another snapshot memory of array section grew by 3k in small amount of time, here is my code:
Main:
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
-- Classes
local Slot = require(System.Slot)
-- Settings
local GuiSlotInputs = {
[Enum.UserInputType.MouseButton1] = "OnClicked"
}
-- Extensions
local Functions = require(script.Functions)
-- Player related
local player = Players.LocalPlayer
local mouse = player:GetMouse()
-- Instances & Folders
local Inventories = ReplicatedStorage:WaitForChild("Inventories")
local InventoryGui = player.PlayerGui:WaitForChild("Inventory")
-- Unasigned / Empty
local selectedSlot
local DisplayedSlots = {}
local HoldingFrame
--==[[FUNCTIONS]]==--
local function Initialize()
for i = 1, 100 do
local newSlot = Slot(InventoryGui.Main.Display, i)
DisplayedSlots[i] = newSlot
if i%2 == 0 then newSlot.Card = "ExampleCard" continue end
newSlot.SlotFrame.Image = "rbxassetid://"
end
end
local function OnMouseMoved()
if InventoryGui.Main.Visible then
local CurrentlyHoveringOver = player.PlayerGui:GetGuiObjectsAtPosition(mouse.X, mouse.Y)
if HoldingFrame then
HoldingFrame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
end
if #CurrentlyHoveringOver > 0 then
for _, GuiObject in CurrentlyHoveringOver do
if selectedSlot and not table.find(CurrentlyHoveringOver, selectedSlot) then selectedSlot.BorderSizePixel = 0; selectedSlot = nil end
if GuiObject.Parent == InventoryGui.Main.Display then
if not selectedSlot then selectedSlot = GuiObject; selectedSlot.BorderSizePixel = 5 end
end
end
else
if selectedSlot then selectedSlot.BorderSizePixel = 0; selectedSlot = nil end
end
table.clear(CurrentlyHoveringOver)
CurrentlyHoveringOver = nil
end
end
local function OnInput(input: InputObject, state: boolean)
local InputFunction = Functions[GuiSlotInputs[input.UserInputType]] or Functions[GuiSlotInputs[input.KeyCode]]
if selectedSlot then
local SlotData = DisplayedSlots[tonumber(selectedSlot.Name)]
InputFunction(SlotData, state)
HoldingFrame = Functions:GetHoldingFrame()
else
InputFunction({}, state)
HoldingFrame = nil
end
InputFunction = nil
end
--==[["CONNECTIONS & CALLBACKS"]]==--
Initialize()
mouse.Move:Connect(OnMouseMoved)
UserInputService.InputBegan:Connect(function(input: InputObject)
if GuiSlotInputs[input.UserInputType] or GuiSlotInputs[input.KeyCode] then
OnInput(input, true)
end
end)
UserInputService.InputEnded:Connect(function(input: InputObject)
if GuiSlotInputs[input.UserInputType] or GuiSlotInputs[input.KeyCode] then
OnInput(input, false)
end
end)
Functions:
local Functions = {}
-- Unasigned
local CurrentlyHeld
local HoldingFrame
local PreviousSlot
function Functions.OnClicked(SlotInfo: Object, state: boolean)
if state and not CurrentlyHeld and rawget(SlotInfo, "Card") then
CurrentlyHeld = SlotInfo.Card
HoldingFrame = SlotInfo.SlotFrame:Clone()
HoldingFrame.Parent = SlotInfo.SlotFrame.Parent.Parent.Parent
PreviousSlot = SlotInfo
SlotInfo.Card = nil
SlotInfo.SlotFrame.Image = "rbxassetid://"
elseif not state and CurrentlyHeld and rawget(SlotInfo, "Id") and not rawget(SlotInfo, "Card") then
SlotInfo.Card = CurrentlyHeld
SlotInfo.SlotFrame.Image = "rbxasset://textures/ui/GuiImagePlaceholder.png"
CurrentlyHeld = nil
HoldingFrame:Destroy()
HoldingFrame = nil
PreviousSlot = nil
elseif not state and CurrentlyHeld then
PreviousSlot.Card = CurrentlyHeld
PreviousSlot.SlotFrame.Image = "rbxasset://textures/ui/GuiImagePlaceholder.png"
PreviousSlot = nil
CurrentlyHeld = nil
HoldingFrame:Destroy()
HoldingFrame = nil
end
end
function Functions:GetHoldingFrame()
return HoldingFrame
end
return Functions
Slot Class:
--==[[SELF]]==--
local System = script.Parent
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Class
local ISOS = require(ReplicatedStorage:WaitForChild("Libraries").ISOS)
local EVENTS = require(ReplicatedStorage:WaitForChild("Libraries").EVENTS)
local Slot = ISOS.newClass({})
--==[[PUBLIC]]==--
function Slot:__init(Parent: Instance, SlotId: number)
self.SlotFrame = script.Template:Clone()
self.SlotFrame.Name = SlotId
self.SlotFrame.Parent = Parent
self.Id = SlotId
end
-- Add/Remove are unused for now
function Slot:AddCard(Card: any)
self.Card = Card
--TODO: Add Card to slot
end
function Slot:RemoveCard()
self.Card = nil
--TODO: Remove Card from slot
end
return Slot
Idk if i should be scared, because players will move around slots a lot of times, not for 3 minutes but for a lot more, is there any solution to this?