Hello Fellow Roblox Devs!
I hope you all are doing well and your creativity is flowing non-stop! I’ve been neck-deep in developing an RPG game and I’ve reached a roadblock that’s been a thorn in my side for a couple of days now.
I’ve been working on scripting a GUI that will display the player’s inventory. I’m aiming for something that’s easy-to-use and attractive at the same time. My current script has the inventory pop up when the player presses ‘I’, but there’s an odd delay and the items are not showing up correctly.
Here’s a snippet of the script I’m using:
-- Inventory script
local player = game.Players.LocalPlayer
local inventory = player:WaitForChild("Inventory")
local openKey = Enum.KeyCode.I
local UIS = game:GetService("UserInputService")
local inventoryUI = script.Parent
local function openInventory(input)
if input.KeyCode == openKey then
inventoryUI.Visible = not inventoryUI.Visible
end
end
-- Connect function to key press event
UIS.InputBegan:Connect(openInventory)
The delay occurs when the player presses ‘I’, it takes a few seconds for the inventory to show up. For the inventory display, I’m using a simple GridLayout and adding UI elements as child objects. I’m not getting any errors in the output, which makes this problem even more vexing.
Could someone point out if I’m missing something, or recommend a more efficient way to script this? Any help would be greatly appreciated.
On a side note, I’d also appreciate any suggestions or best practices for GUI design on Roblox. This is one area I’ve always found challenging and any advice would be invaluable.
Thanks a ton in advance! Looking forward to hearing from you, awesome devs.
Best,
AbigailWhite
P.S: I hope this post is in the right category. If not, kindly guide me to the correct one.