Problem with leaderstats and intValues

Hey everyone!
So I created leaderstats folder that contains some values for the game. One of them is flowers. And basically what happens is if you have 0 flowers and you collect 5 of them, then you can sell them in the shop and get coins and it will reduce flower count. And here is the problem. When you collect one more flower it will add 1 to previous count (in this case 5) so you will have 6 instead of 1.
Idk what am I doing wrong:
I use simply:
player:WaitForChild("Flowers"):WaitForChild("Lily").Value
to get flower count.
If anyone has any ideas I would like to hear them :slight_smile:

It’s a problem with how you’re updating the value then, not with how you’re fetching it. Review your systems for any issues. You can also apply various fixes, such as clamping the value between 0 and 5 or however your maximum values are calculated.

By the way, daisy chaining WaitForChild is bad practice and especially when you’re assuming that they’ll be returning truthy values. Use WaitForChild only if you need something to exist and you aren’t sure it’ll exist when you need it. In all other cases, player.Flowers.Lily will work and you can use any error messages as indication of bad code structuring or that you did something wrong.

1 Like

I got it working. I’m not sure if is that a problem but I was updating it trough the server script, so I added Remote Event and updated it from the local script and it worked perfectly, I’m not sure what I’m missing…
Thanks for your advice :slight_smile: