So I Am Making A Inventory System And I Cant Quite Figure Out How Do I Fix My Code
The Problem Is To Shift Things From Inventory To HotBar And From HotBar To Inventory
Main LocalScript
`local Tools = {}
local MaxINV = 3
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
local Num = 0
local Inventory = {}
local InvFilled = false
local HotFilled = false
local db = false
local Restrict = 0
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:Connect(function()
if not db then
db = true
if Mouse.Target ~= nil and Mouse.Target.Parent:IsA(“Tool”) then
if not InvFilled then
print(“Can Pick”)
Mouse.Target.Parent.Parent = game.Players.LocalPlayer.Backpack
else
Restrict = 3
print(“Cant Pick Inventory Filled”)
end
end
wait(0.1)
db = false
end
end)
local NumToWords = {
[1] = “One”,
[2] = “Two”,
[3] = “Three”,
[4] = “Four”,
[5] = “Five”,
[6] = “Six”,
[7] = “Seven”,
[8] = “Eight”,
[9] = “Nine”,
[10] = “Zero”,
}
local messdisplayed = false
– Updates Hotbar
local function updatehotbar()
– Deletes Old Stuff
for i,v in pairs(script.Parent.Frame:GetChildren()) do
if v:IsA(“TextButton”) then
v:Destroy()
end
end
– Cap
if #Tools > 10 then
table.insert(Inventory,#Inventory+1,Tools[#Tools])
table.remove(Tools,#Tools)
if #Inventory < MaxINV then
local temp = script.Temp:Clone()
temp.Parent = script.Parent.Inventory.StoreArea
temp.Text = Inventory[#Inventory].Name
temp.Num:Destroy()
temp.Name = Inventory[#Inventory].Name
InvFilled = false
else
local object = Inventory[#Inventory]
table.remove(Inventory,#Inventory)
end
if #Inventory > MaxINV-2 then
Restrict = 2
print("Inventroy Filled ", Inventory)
InvFilled = true
end
elseif #Tools == 10 then
if not messdisplayed then
messdisplayed = true
Restrict = 1
HotFilled = true
end
else
HotFilled = false
end
– Makes Stuff
for i,v in pairs(Tools) do
for _,L in pairs(script.Parent.Frame:GetChildren()) do
if L.Name == v.Name then
L:Destroy()
end
end
local temp = script.Temp:Clone()
if #Tools < 11 then
temp.Parent = script.Parent.Frame
end
if i == 10 then
temp:WaitForChild(‘Num’).Text = 0
else
temp:WaitForChild(‘Num’).Text = i
end
temp.Text = v.Name
temp.Name = v.Name
end
for i,v in pairs(script.Parent.Inventory.StoreArea:GetChildren()) do
if v:IsA(“TextButton”) then
local BoolValue = Instance.new(“BoolValue”,v)
BoolValue.Name = “InventroyItem”
for u,c in pairs(v:GetChildren()) do
if c:FindFirstChild(“InventoryItem”) and c.InventoryItem ~= BoolValue then
print(c.Name)
c.InventoryItem:Destory()
end
end
end
end
end
– NewTool Added
local Childd
game.Players.LocalPlayer.Backpack.ChildAdded:Connect(function(Child)
if Child ~= Childd and #Tools < 11 then
table.insert(Tools,#Tools+1,Child)
Num =Num + 1
end
updatehotbar()
end)
– Tool Removed
game.Players.LocalPlayer.Backpack.ChildRemoved:Connect(function(Child)
if Child.Parent ~= game.Players.LocalPlayer.Character then
table.remove(Tools,Tools[Child])
Num =Num - 1
messdisplayed = false
else
Childd = Child
end
updatehotbar()
end)
– When Tool Is Picked
game.Players.LocalPlayer.Character.ChildAdded:Connect(function(Child)
if Child ~= Childd then
game.ReplicatedStorage.UnEquipTools:FireServer()
end
end)
local equipped = false
local db = false
– Unequip / Equip
game:GetService(“UserInputService”).InputBegan:Connect(function(In)
for i,v in pairs(Tools) do
if In.KeyCode == Enum.KeyCode[NumToWords[i]] and v.Parent == game.Players.LocalPlayer.Backpack or v.Parent == game.Players.LocalPlayer.Character then
if not db then
db = true
if not equipped then
equipped = true
game.ReplicatedStorage.EquipTools:FireServer(v)
for _,Label in pairs(script.Parent.Frame:GetChildren()) do
if Label.Name == v.Name then
EquippedItem = Label.Stroke
EquippedItem.Thickness = 5
end
end
wait(0.1)
for _,Label in pairs(script.Parent.Frame:GetChildren()) do
if Label.Name == v.Name then
EquippedItem = Label.Stroke
EquippedItem.Thickness = 5
end
end
else
if In.KeyCode == Enum.KeyCode[NumToWords[i]] then
EquippedItem.Thickness = 0
game.ReplicatedStorage.UnEquipTools:FireServer()
equipped = false
end
end
wait(0.2)
db = false
end
end
end
end)
– Restrictions
game:GetService(“RunService”).Heartbeat:Connect(function()
if Restrict == 1 then
Restrict = 0
local ResClone = script.Parent.Restrict:Clone()
ResClone.Parent = script.Parent
local TS = game:GetService(“TweenService”)
local Info = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
local Tween1 = TS:Create(ResClone,Info,{TextTransparency = 1})
local Tween2 = TS:Create(ResClone.UIStroke,Info,{Transparency = 1})
ResClone.TextTransparency = 0
ResClone.UIStroke.Transparency = 0
ResClone.Text = “HotBar Filled!”
ResClone:TweenPosition(UDim2.new(0.3, 0,0.18, 0),“Out”,“Sine”,2)
wait(0.2)
Tween1:Play()
Tween2:Play()
wait(2)
ResClone:Destroy()
elseif Restrict == 2 then
Restrict = 0
local ResClone = script.Parent.Restrict:Clone()
ResClone.Parent = script.Parent
local TS = game:GetService(“TweenService”)
local Info = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
local Tween1 = TS:Create(ResClone,Info,{TextTransparency = 1})
local Tween2 = TS:Create(ResClone.UIStroke,Info,{Transparency = 1})
ResClone.TextTransparency = 0
ResClone.UIStroke.Transparency = 0
ResClone.Text = “Inventory Filled!”
ResClone:TweenPosition(UDim2.new(0.3, 0,0.18, 0),“Out”,“Sine”,2)
wait(0.2)
Tween1:Play()
Tween2:Play()
wait(2)
ResClone:Destroy()
elseif Restrict == 3 then
Restrict = 0
local ResClone = script.Parent.Restrict:Clone()
ResClone.Parent = script.Parent
local TS = game:GetService(“TweenService”)
local Info = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
local Tween1 = TS:Create(ResClone,Info,{TextTransparency = 1})
local Tween2 = TS:Create(ResClone.UIStroke,Info,{Transparency = 1})
ResClone.TextTransparency = 0
ResClone.UIStroke.Transparency = 0
ResClone.Text = “Inventory Is Full!”
ResClone:TweenPosition(UDim2.new(0.3, 0,0.18, 0),“Out”,“Sine”,2)
wait(0.2)
Tween1:Play()
Tween2:Play()
wait(2)
ResClone:Destroy()
end
end)
local UIS = game:GetService(‘UserInputService’)
local dragToggle = nil
local dragSpeed = 0.25
local dragStart = nil
local startPos = nil
game:GetService(“RunService”).Stepped:Connect(function()
for _,frame in pairs(script.Parent.Inventory.StoreArea:GetChildren()) do
if frame:IsA(“TextButton”) then
local function updateInput(input)
local delta = input.Position - dragStart
local position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X,
startPos.Y.Scale, startPos.Y.Offset + delta.Y)
game:GetService('TweenService'):Create(frame, TweenInfo.new(dragSpeed), {Position = position}):Play()
end
frame.InputBegan:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) then
dragToggle = true
frame.Parent = script.Parent
dragStart = input.Position
startPos = frame.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
local Ongui = false
script.Parent.Frame.MouseEnter:Connect(function()
Ongui = true
end)
script.Parent.Frame.MouseLeave:Connect(function()
Ongui = false
end)
if Ongui then
table.insert(Inventory,#Tools)
table.remove(Tools,#Tools)
table.remove(Inventory,Inventory[table.find(Inventory,frame)])
table.insert(Tools,#Tools,frame)
frame:Destroy()
updatehotbar()
else
frame.Parent = script.Parent.StoreArea
end
dragToggle = false
end
end)
end
end)
UIS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
if dragToggle then
updateInput(input)
end
end
end)
end
end
end)`
HotBarInv.rbxm (16.3 KB)
This Is The Model Of It
All I Want Is It To Drag The Item In Inventory And Put It In The Slot Where The Player Stop Dragging It.
Thanks =D
Steve