Right now its not too much, but i dont really know if it will work alright in a decent made game
local script code in the gui
local player = game.Players.LocalPlayer
local mainFolder = game.ReplicatedStorage.PlayerInvetorys:WaitForChild(player.Name .. "Folder")
local inv = mainFolder:WaitForChild("Inventory")
local hb = mainFolder:WaitForChild("Hotbar")
local CurrentInv = inv:GetChildren()
local C = game.ReplicatedStorage.ItemFrame
local hoverinv = script.Parent.Parent.HoverInfo
local mouse = player:GetMouse()
local InventoryFrames = {}
print(CurrentInv)
function equipitem(item, frame)
if not item then warn("Wheres My Gun At?") return end
hoverinv.Visible = false
game.ReplicatedStorage.TotallyCoolEvents.EquipGun:FireServer(item)
end
local function Hover(item)
hoverinv.Visible = true
if item:FindFirstChild("strings") then
hoverinv.GunName.Text = item.Name
hoverinv.ExpNumber.Text = item.strings.CurrentExp.Value .. " / " .. item.strings.ReqExp.Value
hoverinv.LvlNumber.Text = item.strings.GunLevel.Value
hoverinv.GunDmg.Text = item.strings.Damage.Value
hoverinv.GunRPM.Text = item.strings.FireRate.Value
hoverinv.GunAmmo.Text = item.strings.Ammo.Value .. " / " .. item.strings.StoredAmmo.Value
hoverinv.Tal1.Text = item.strings.T1.Value .. " | Unlocks @ Level " .. item.strings.ReqT1.Value
hoverinv.Tal2.Text = item.strings.T2.Value .. " | Unlocks @ Level " .. item.strings.ReqT2.Value
hoverinv.Tal3.Text = item.strings.T3.Value .. " | Unlocks @ Level " .. item.strings.ReqT3.Value
hoverinv.Tal4.Text = item.strings.T4.Value .. " | Unlocks @ Level " .. item.strings.ReqT4.Value
end
end
function Creation(item)
local K = C:Clone()
InventoryFrames[item] = K
K.Text = item.Name
K.Visible = true
K.Parent = script.Parent.ISF
K.MouseButton1Click:Connect(function()
print(InventoryFrames)
equipitem(item, K)
end)
K.MouseEnter:Connect(function()
Hover(item)
end)
K.MouseLeave:Connect(function()
hoverinv.Visible = false
end)
end
function Deletion(item)
local frame = InventoryFrames[item]
frame:Destroy()
InventoryFrames[item] = nil
end
for i, v in ipairs(CurrentInv) do
Creation(v)
end
inv.ChildAdded:Connect(function(Child)
Creation(Child)
end)
inv.ChildRemoved:Connect(function(Child)
Deletion(Child)
end)
mouse.Move:Connect(function()
if script.Parent.Visible == true then
hoverinv.Position = UDim2.new(0,mouse.X,0,mouse.Y)
end
end)
Script where remote event is fired to
game.ReplicatedStorage.TotallyCoolEvents.EquipGun.OnServerEvent:Connect(function(plr, d)
local Char = plr.Character
if not d then return end
if not Char then return end
if not d:IsA("Tool") then return end
if Char:FindFirstChildWhichIsA("Tool") then
d.Parent = plr.Backpack
else
d.Parent = Char
end
end)
And the script that creates a folder on join
game.Players.PlayerAdded:Connect(function(plr)
local c = Instance.new("Folder", game.ReplicatedStorage.PlayerInvetorys)
c.Name = plr.Name .. "Folder"
local d = Instance.new("Folder", c)
d.Name = "Inventory"
local e = Instance.new("Folder", c)
e.Name = "Hotbar"
end)
Mainly looking on stuff i could add to improve it / “make the code better”
(Edit)
Heres a video on how it currently works
(Edit 2)
A little bit more shown in this video how it works
(Edit 3 / 4)
Updated code with some help i got from