Ok so, I often see popular games with cool hotbars, I wonder how can I do it, I searched youtube, but I didn’t find any basic ones. Thanks in advance
One approach to this would be to create a ScreenGui
in place of where the hotbar normally is, then adding a GuiButton
. Program those buttons to send an Event using RemoteEvent
whenever you need to equip/unequip. To fetch their current inventory, you can use a RemoteFunction
.
Before all of that happens, you need to disable the Backpack using StarterGui
on a LocalScript.
-- Inventory Manager
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local RemoteFunction = game.ReplicatedStorage.RemoteFunction
function Unequip(Player)
local Tool = Player.Character:FindFirstChildOfClass("Tool")
if Tool then Tool.Parent = Player.Backpack return true else return false end
end
RemoteEvent.OnServerEvent:Connect(function(Player, Item, Equip)
if Player and Player.Backpack and Player.Backpack:FindFirstChild(Item) then
if Equip then
Unequip(Player)
Player.Backpack:FindFirstChild(Item).Parent = Player.Character
else
Unequip(Player)
end
end
end)
RemoteFunction.OnServerInvoke = function(Player)
return Player.Backpack:GetChildren()
end
-- LocalScript, to Handle Generating the Gui
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local RemoteFunction = game.ReplicatedStorage.RemoteFunction
local Backpack = RemoteFunction:InvokeServer()
for k, v in pairs(Backpack) do
-- Gui Code Here
end
-- Part of LocalScript that Equips/Unequips Tools
for k, v in pairs(GuiButtons) do
-- Assuming 'k' is the item name
local ToEquipBool = Instance.new("BoolValue", v)
ToEquipBool.Name = "ToEquip"
ToEquipBool.Value = false
v.MouseButton1Click:Connect(function()
local ToEquip = not v.ToEquip.Value
-- Code to Handle Button Animations
RemoteEvent:FireServer(k, ToEquip)
end
end
11 Likes
Thanks so much! This helped me alot!
2 Likes