Dynamically Updating a Hotbar

So, for the first time I’m looking into developing a Hot Bar. To get tips/hints/ideas I’ve looked at some models. They all seem to work on a similar premise, chiefly creating ‘slots’, setting off a loop, and then populating the slots via a ‘TempSlot’, for example:

I think I understand the concept, and it’s a neat way of getting some control over the design. However, if I understand this correctly, the hotbar is populated every time a player joins the game or respawns? All good, but, what happens if I want to dynamically update during the game while the player is alive and kicking?

To clarify, I want to create a small circle at the bottom right of each icon (weapon), with a TextLabel inside. This textlabel can then be updated via player variables during the game. This means I can add an ‘ammo quantity’ to the weapon which decreases after every shot. Here’s an example of how it should look:

image

And this is as far as I’ve got. The “3” in the white circle can be loaded with whatever number, from whatever variable, on entering the game or respawning, but during an intense melee, for example? … logically, not working. Once generated those slots are fixed, no children/dependents to access or write to.
If I change any variables in the TempSlot, mid-game, nothing happens, either, because logically the TempSlot is nothing more than a temporary container.

I’ve seen this work in other games, but I’m not seeing how this is logically possible. I’m certainly no ‘Pro’ and still very much learning, but this has me scratching my head.

I’m not looking for code/script - that’s not the way I like to work. Anyway, I’ve been trying so many ideas, trying to get this to work, the code’s all over the place, by now. I learn way more by struggling through things myself. But, if anyone knows of any good tutorials or guidance anywhere, that would be great!!
(Or if anyone was willing to take the time to guide me through this privately, I’d willingly make it profitable :-))

Please don’t post some random tutorial from YouTube. I think I’ve been through every one of those. They all seem to cover the exact same approach I’ve detailed above, but NO OPTION to change variables inside the hotbar ‘on-the-fly’. That said, maybe there’s a tutorial somewhere, that I’ve missed.

Thanks for any help!! Truly appreciated :slight_smile:

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

3 Likes

Can you elaborate on what you want to update?

1 Like

Thanks for the reply :slight_smile:

So, lets say for example that a player gets a ‘bomb’ as a tool (for example the ‘fuse bomb’ in Studio.) As it stands, the player can use that bomb with no limits - drop multiple versions of that bomb wherever they need to.

I want to limit the player to using the bomb, say, 10 times, and then gray the button out, until the player has ‘recharged’ the bomb. A small circle is added to the holder in the GUI, bottom-right of the icon, as per my screenshot. This number represents the amount of times the player can use that button before it disables (grayed-out) and counts down per shot/explosion … 10 to 0.

Here’s an example of a customizable hotbar. If you take a look, you might get a better idea. Basically, how would I put a ‘use limit’ on specific tool, and gray the button out once it’s ‘spent’ … all ‘dynamicallyduring the game (not on join or respawn):
CustomizableHotBar.rbxl (75.1 KB)

Yes, I know I can store information in the tool itself, add a variable, tweak that variable, add a countdown, disable the weapon when there’s no ammo/charge. I’m confident doing that, and that’s not really the issue. It’s ‘cosmetic’, more than anything - more an issue with the GUI and how I display specific weapon stats to the player.

In the GUI itself, if I can’t directly reference the tool specifically by name, as a child, once it’s added to it’s slot on start-up, then that avenue seems blocked.
Theoretically it all seems possible, and I’ve seen it in other games.

I’m aware I might not be explaining this too well, but I’ve given it a go!

Again, I’m not asking for script … Just pointers and suggestions :slight_smile:

2 Likes

So in basic terms you want the ammo to display on the hotbar and when the ammo is 0 you can’t drop a bomb?

1 Like

You will update the text label that shows the ammo every time the person shoots.

1 Like

Lol … Yes, basically that.
I could have put it a little clearer. Been a long day :-/

1 Like

You can use attributes or IntValues to store the ammo count and use events such as .Changed or GetPropertyChangedSignal("TheValueYouWantToListenForChanges") then update the text label with the new count.

1 Like

Yes!!! Thank you.

I’ve just experimented with GetPropertyChangedSignal and it’s doing the job perfectly.
I hadn’t investigated that event before (I’m still learning) but now I’ve understood it, it opens up a world of possibilities :slight_smile:

Again, thanks so much! I wanted to be ‘pointed’ in the right direction, and I was. I love this forum … You guys are awesome :slight_smile:

1 Like