so i have an inventory system that makes it so that whenever a player getts a new skill it adds it to the hotbar, if there is no space in the hotbar it adds it to the inventory.
now im trying to make it so that if the player drags the skill into there backpack it goes into there backpack, if they drag it onto there hotbar it goes onto there hotbar. Additonally it would be able to switch positions with other slots and rearrange them.
Ive tried a couple of methods to making this work such as including a draggable folder since the ui gridlayout doesnt work with it,
if anyone knows how to do this feel free to reply.
Inventory system (1).rbxl (74.6 KB)
--[[
Handles everything that has to do with the inventory on the client.
--]]
local context_action_service = game:GetService "ContextActionService"
local replicated_storage = game:GetService "ReplicatedStorage"
local starter_gui = game:GetService "StarterGui"
local players = game:GetService "Players"
local slot_template = replicated_storage:WaitForChild "HotbarSlot"
local remotes = replicated_storage:WaitForChild "Remotes"
local add_tool = remotes:WaitForChild "AddTool"
local player = players.LocalPlayer
local player_gui = player.PlayerGui
local hotbar = player_gui:WaitForChild "Hotbar"
local inventory = player_gui:WaitForChild "Inventory"
local keybinds = player_gui:WaitForChild "Keybinds"
--handles adding UI for a given tool previously added by the server.
add_tool.OnClientEvent:Connect(function(skill_name: string)
local s = slot_template:Clone()
for _, slot: Frame in ipairs(keybinds.Frame:GetChildren()) do
if not slot:IsA "TextLabel" or slot.Taken.Value then continue end
s.Position = slot.Position
s.Parent = hotbar.Frame
slot.Taken.Value = true
return--we've found a valid slot, so we store it here
end
--at this point we haven't found a valid slot, so we put this in the inventory
s.Visible = false
s.Parent = inventory.ScrollingFrame
end)
--handles toggling the inventory
context_action_service:BindAction("ToggleInventory", function(_, state: Enum.UserInputState, input: InputObject)
if state ~= Enum.UserInputState.Begin then return end
keybinds.Enabled = not keybinds.Enabled
inventory.Enabled = not inventory.Enabled
end, false, Enum.KeyCode.Backquote)
starter_gui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)