Hello, I really want to make my own hotbar for my games. I have made the GUI but all I need now is help with the scripting. Could anyone tell me how to get the characters inventory?
Thanks
Hello, I really want to make my own hotbar for my games. I have made the GUI but all I need now is help with the scripting. Could anyone tell me how to get the characters inventory?
Thanks
For the question in your post, getting the contents of someone’s inventory is simple:
local backpack = game:GetService("Players").LocalPlayer.Backpack
local listContents = backpack:GetChildren()
That won’t make your GUI work. You might have the GUI, but you still need a framework for everything. You’ll have to connect functions to input events, create new icons for every tool. I don’t know how much you progressed, but given this question, I doubt it’s a lot.
For the icons, you will have to create an ImageButton with an ViewportFrame inside it. The button is to give it a frame like appearance (or you could just use the BorderPixelSize property), while the viewport will give a thumbnail for the tool (you could use just ImageLabels in case you already have an image for each tool; otherwise, you will have to align the tools depending on their boundary size so they stay inside the frame).
You will then have to connect functions for mouse clicks. MouseButton1Click for left and MouseButton2Click for right mouse button. I don’t know the layout, but if you can ignore the right button if you don’t want to make a drop-down menu.
Next up, unless you are ready to work on caching, you will have to clear all the icons when the GUI is closed and reload all of them when you open it. The 2nd line of the “code” I posted will only return a table containing all the currently present tools. Anything picked up afterwards won’t show up in it. In other words, you will have to run local listContents = backpack:GetChildren()
every time you open the GUI.
I know how I will make the rest, that’s the bit I couldn’t get. Thanks a lot!