From a79367876de16190e50c9781318ba8a8697eda13 Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Fri, 5 Dec 2025 21:26:37 +0000 Subject: [PATCH 1/6] Add event code sample Signed-off-by: GitHub --- docs/api-reference.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/api-reference.md b/docs/api-reference.md index ebdc9dd..43542e8 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -4,7 +4,9 @@ Purse unlocks APIs for the CoreGui backpack which were previously locked to othe ## Methods -``` lua title="LocalScript - Inventory Toggle Button" linenums="1" +The following code sample, placed within a child `LocalScript` of a `GuiButton`, uses [`OpenClose()`](#openclose) to toggle the inventory on the button's `Activated` event. + +``` lua title="Inventory Toggle Button" linenums="1" local ReplicatedStorage = game:GetService("ReplicatedStorage") local Purse = require(ReplicatedStorage.Purse) @@ -86,6 +88,22 @@ Returns true. ## Events +The following code sample, placed within a child `LocalScript` of `StarterPlayerScripts`, uses [`StateChanged`](#statechanged) detect when the inventory is toggled and prints it's state to output. + +``` lua title="Detect Inventory State" linenums="1" +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +local Purse = require(ReplicatedStorage.Purse) + +Purse.StateChanged.Event:Connect(function(isNowOpen) + if isNowOpen then + print("Inventory opened") + else + print("Inventory closed") + end +end) +``` + ### StateChanged ``` From 2be22ca4c4358cc06246330d1f0eff38a901564b Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Fri, 5 Dec 2025 23:06:57 +0000 Subject: [PATCH 2/6] Update icon logic to account for manually toggling the inventory Signed-off-by: GitHub --- src/TopbarIcon.client.luau | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/TopbarIcon.client.luau b/src/TopbarIcon.client.luau index 79e1ec2..bbdbd51 100644 --- a/src/TopbarIcon.client.luau +++ b/src/TopbarIcon.client.luau @@ -17,15 +17,16 @@ icon:autoDeselect(false) icon:setOrder(-1) icon:bindToggleKey(Enum.KeyCode.Backquote) -UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean): () - local inputType = input.UserInputType - if not gameProcessedEvent then - if inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch then - icon:deselect() - end +BackpackScript.StateChanged.Event:Connect(function(isNowOpen) + if isNowOpen then + icon:select() + else + icon:deselect() end end) -icon.toggled:Connect(function(): () - BackpackScript.OpenClose() +icon.toggled:Connect(function(_isSelected, fromSource) + if fromSource == "User" then + BackpackScript.OpenClose() + end end) From a63fda901d7614012ade4b02daab5763c67ed184 Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Fri, 5 Dec 2025 15:13:50 -0800 Subject: [PATCH 3/6] Remove unused UserInputService variable Removed unused UserInputService import. Signed-off-by: Ryan Luu --- src/TopbarIcon.client.luau | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/TopbarIcon.client.luau b/src/TopbarIcon.client.luau index bbdbd51..dc53e03 100644 --- a/src/TopbarIcon.client.luau +++ b/src/TopbarIcon.client.luau @@ -1,7 +1,5 @@ --!strict -local UserInputService = game:GetService("UserInputService") - local BackpackScript = require(script.Parent) local Icon = require(script.Parent.Parent.topbarplus) From e213ac98fb5e37f4d9ceb8ca1c1fbde7d15138c5 Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Fri, 5 Dec 2025 15:14:26 -0800 Subject: [PATCH 4/6] Change icon image variables to uppercase Signed-off-by: Ryan Luu --- src/TopbarIcon.client.luau | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TopbarIcon.client.luau b/src/TopbarIcon.client.luau index dc53e03..3718de2 100644 --- a/src/TopbarIcon.client.luau +++ b/src/TopbarIcon.client.luau @@ -3,8 +3,8 @@ local BackpackScript = require(script.Parent) local Icon = require(script.Parent.Parent.topbarplus) -local iconSelectedImage = "rbxasset://textures/ui/TopBar/inventoryOn.png" -local iconDeselectedImage = "rbxasset://textures/ui/TopBar/inventoryOff.png" +local ICON_SELECTED_IMAGE = "rbxasset://textures/ui/TopBar/inventoryOn.png" +local ICON_DESELECTED_IMAGE = "rbxasset://textures/ui/TopBar/inventoryOff.png" local icon = Icon.new() icon:setCaption("Inventory") From a87a4a03e0684fb3fce40ec62255c9a8e5f8ad3c Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Fri, 5 Dec 2025 15:14:38 -0800 Subject: [PATCH 5/6] Fix image constants in TopbarIcon.client.luau Signed-off-by: Ryan Luu --- src/TopbarIcon.client.luau | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TopbarIcon.client.luau b/src/TopbarIcon.client.luau index 3718de2..730112c 100644 --- a/src/TopbarIcon.client.luau +++ b/src/TopbarIcon.client.luau @@ -8,8 +8,8 @@ local ICON_DESELECTED_IMAGE = "rbxasset://textures/ui/TopBar/inventoryOff.png" local icon = Icon.new() icon:setCaption("Inventory") -icon:setImage(iconSelectedImage, "Selected") -icon:setImage(iconDeselectedImage, "Deselected") +icon:setImage(ICON_SELECTED_IMAGE, "Selected") +icon:setImage(ICON_DESELECTED_IMAGE, "Deselected") icon:setImageScale(1) icon:autoDeselect(false) icon:setOrder(-1) From 0e976e4e2c1071fbceea3f3fbec38ff4a09cbf23 Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Fri, 5 Dec 2025 15:21:22 -0800 Subject: [PATCH 6/6] Fix grammar Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Ryan Luu --- docs/api-reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-reference.md b/docs/api-reference.md index 43542e8..be0fa36 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -88,7 +88,7 @@ Returns true. ## Events -The following code sample, placed within a child `LocalScript` of `StarterPlayerScripts`, uses [`StateChanged`](#statechanged) detect when the inventory is toggled and prints it's state to output. +The following code sample, placed within a child `LocalScript` of `StarterPlayerScripts`, uses [`StateChanged`](#statechanged) to detect when the inventory is toggled and prints its state to output. ``` lua title="Detect Inventory State" linenums="1" local ReplicatedStorage = game:GetService("ReplicatedStorage")