So at times I have heard that badgeservice can be very expensive. I would like to know when to save simple stuff like ‘acquired 10,000 power’, or ‘reached level 5’, in the most effective way so that the game doesn’t lag.
In my opinion you could of try to save it in a table with strings name of the badges or just create a boolvalues once player joins the game and saves a boolvalues. So basically let’s say a default value of boolvalue is false and if they achieved a badge it turns to true and this value should save to datastore. I hope this helps.
yes and when badgeservices saved to the string your thinking that too?
I mean yea, you don’t really need to save anything because it does API on roblox already just use a UserHasBadge function and it returns you if this player has already this badge or not? I am not really sure if I am correct about understanding your problem. I hope this helps.
Personally i check for all the badges the player owns (that belong to the place obviously) and store them in their stats temporarily using the badge ID. I do it like this so you only need to check if they own a badge (using the roblox UserHasBadge function) once. When it comes time to award a badge ill check their temporary stats to see if they have the badge, if they own it do nothing. If they don’t own it then Award the badge using the roblox API and then store it in their temporary badge stats. Think of it kinda like a datastore, you don’t want to use GetAsync every time you want to get someones player data, instead you just refer to the table of stats that was cached.
Hope this makes sense!
Heard from who? BadgeService isn’t expensive, what’s expensive is probably your code work behind awarding badges. Hopefully you aren’t using loops and you’re using changed signals for an event-based system.
That being said, that’s your answer. Just hook a changed signal to each value. When it changes, check if the value is at or above a certain value needed to earn the badge. If so, use UserHasBadge to check if the player has the badge or not. If they do not, award it.