Module - BadgeService2

Hello, I recently made this for fun, and testing, and decided to allow people to use it.

This module keeps caching for BadgeService requests. And does all the job for you.

I need people to help me test this, as I am not buying a badge… Lol! (Hey, roblox, can we have badge testing…?)

Functions… (only one lol)

BadgeService2.AwardBadge(plr, badgeId)

Differently from the actual BadgeService, BadgeService2 only allows you to award badges using the player object, and not their userId.

It has two arguments, 1st being the player object, and second one being the badgeId you wanna give to the player;

Example using code:

local BadgeService = require(game.ServerScriptService:WaitForChild("BadgeService2"))

local badgeId = 1285135246 -- fake number, i don't have one.
game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = plr:WaitForChild("leaderstats")
	local cash = leaderstats:WaitForChild("Cash")
	local onCashChanged
	onCashChanged = cash:GetPropertyChangedSignal("Value"):Connect(function()
		if cash.Value >= 230 then
			BadgeService.AwardBadge(plr, badgeId)
			-- Or you can do:
			local awarded = BadgeService.AwardBadge(plr, badgeId)
			if awarded == true then
				onCashChanged:Disconnect()
			end
			--
		end
	end)
end)

This function also CAN but maybe won’t, return a value. This value will be true.
If it’s returned as true, that means that the badge was awarded before.
And you can use that data to Disconnect() a event, which you do not need anymore.
I recommend using this method, as it helps on performance.

Module:

Again, this module is on beta, so I need feedback, with errors. Before using it on your game, check if it works. If it doesn’t then message me or reply to this.

If anybody made this before, please let me know.

2 Likes

Is there really any benefit to awarding by the instance and not by the ID? It’s just 7 extra characters to get the UserId – not really big enough of a deal to warrant an entire module, even if it’s still in beta.

7 Likes

Actually, no BUT, it’s more of something I did not realise as I never really used BadgeService before, and I just went with the player instance, I might make compatibility for userIds soon. I just made this, like now.

1 Like

It is a waste of performance to require a module instead of getting the BadgeService and calling AwardBadge with the player UserId. All you have to do is simply indexing the userid property of the player. I don’t really understand the use of this module when it justs wastes memory and only has one function. Plus adding UserId compatibility will just make it the same as the normal BadgeService and have no difference apart from the memory wasted in requiring the module.

Adding more functions not available with using the BadgeService will make this wrapper more useful. Also caching errors that occur and resending the badge awarding to the BadgeService until it successfully is sent will make this more reliable than the regular service.

4 Likes

Caching? Let’s say you have a badge awarded when someone gets level 100 or something, you’ll have to keep on checking if that players has that badge, you can just disconnect the .Changed event…

Here’s an idea for an update: Use datastore to remember if a badge has been awarded or not.


At the moment, players can simply delete badges from their inventory, rejoin a server, and the game will think the badge hasn’t been awarded.


Also, there’s no need to use tostring like this

image

You can index tables using numbers.

2 Likes

I was thinking about that. But in my mind it doesn’t make sense…

Is it a big deal, that they can be re awarded if deleted? Aren’t they supposed to have it anyways? :thinking:

Can I ask why should anyone use this? What’s wrong with the built in BadgeService? Seems like a waste of a module and requiring it, when all you have to do is just use the in built service :face_with_raised_eyebrow:

Faster requests. And less requests to the actual service. Because it has caching :crazy_face::v:

I don’t think many people have problems with BadgeService taking too long to award a badge?

You should check the code example

I appreciate what you’re doing with this, but I can’t see any benefit over using the BadgeService itself. I’m actually typing more characters requiring the module than I would be just getting the BadgeService.

Perhaps you can add some more methods to the module to make it more useful than the BadgeService is?

2 Likes

Coming soon…
image

This will be way bigger than just caching.

@Trifectist

or you could just call the service directly rather than use an abstraction… why does this exist?

1 Like

Caching, less delay essentially.

Not sure if badge service from roblox has a request limit.
But even then… Doesn’t really matter it makes it faster.
But I’m working on v3 as you can see. Might be released soon. This will be a completely different thing which would allow devs to do stuff that they couldn’t do without money…

I took that further LOL

1 Like