AchievementService
Easily Manage and Award Badges
AchievementService is an open-source module designed to make managing and awarding achievements in your games easy and customizable. With built-in support for UI animations, haptics, audio, and more, you can create engaging achievement experiences for your players.
⭐ Features
1. Awarding Badges
AchievementService makes it simple to award badges to players in your game.AchievementService:Award(player, badgeIdentifier) -- badgeIdentifier can either be the BadgeName or BadgeId
That’s it! You can now use either the BadgeName
or the BadgeId
to award a badge, making it even more flexible. AchievementService will use HTTPService and the Roblox API to automatically fetch and manage the available badges for your game.
2. Customizable Animations
AchievementService provides an option to toggle customizable UI animations. It also includes a default animation for easy use. You can either use the default UI or design your own. I recommend using the existing script in the default UI as a template if you decide to create your own.3. Audio Support
AchievementService allows for customizable sounds, allowing you to toggle and add audios. I've also included a pack of 25 classic Roblox audios with the module. lol4. Haptic Feedback
AchievementService even allows for haptics, allowing for tactile response to mobile and possibly console players.5. Fully Open-Source
AchievementService is entirely open-source, allowing you to modify and extend the module as needed for your game.❓ How It Works
When you initialize the module using AchievementService.init()
, it handles badge management based on your chosen configuration:
-
Using HTTPService (Default):
By default, AchievementService fetches all the badges in your game using the Roblox API and compiles them into an internal dictionary. This initialization process only happens once, ensuring that subsequent calls to:Award()
are fast and efficient. Instead of making additional API calls, the module looks up the badge in the pre-compiled dictionary. -
Using Manually Specified BadgeIds:
If you prefer not to use HTTPService, you can set the variableachievementService.UseHTTPService
tofalse
. In this case, the module will rely on a manually specified table of BadgeIds (achievementService.BadgeIds
) to retrieve badge information. -
Fallback Mechanism:
IfachievementService.UseHTTPService
is set totrue
but fetching badges via HTTPService fails, the module can optionally fall back on theachievementService.BadgeIds
table by settingachievementService.BadgeIdFallback
totrue
.
By automating or customizing badge management, AchievementService eliminates the need to manually handle badge IDs in your scripts while offering flexibility to suit your game’s needs. This is particularly helpful for games with a large number of badges or for environments where HTTPService may not always be reliable.
🔨 Installation Guide
1. Import the Module and Configure Badge Method
- Copy the AchievementService module into your game.
-
If you want to use HTTPService (easiest method):
- Enable
Allow HTTP Requests
in your game settings under the security tab.
- Enable
-
If you don’t want to use HTTPService and only use BadgeIds:
- Manually set up the
achievementModule.BadgeIds
table by adding your game’s BadgeIds and set theachievementModule.UseHTTPService
variable tofalse
.
- Manually set up the
-
If you want to use both (most reliable method):
- Manually set up the
achievementModule.BadgeIds
table by adding your game’s BadgeIds and set theachievementModule.BadgeIdFallback
variable totrue
.
- Manually set up the
2. Awarding Badges
- To award an achievement to a player, simply call:
AchievementService:Award(player, badgeIdentifier) -- badgeIdentifier can either be the BadgeName or BadgeId
3. Configuration
-
AchievementService, as of v1.03, allows configuration/customization for the following:
- Toggle animations
- Animation Style (which type of animation)
- Toggle sounds
- Sound (which sound will play)
- Speed Multiplier (how fast an animation plays)
- Toggle haptics
- Toggle HTTPService
- Toggle BadgeIdFallback
- Manually implement BadgeIds
- Toggle Roblox default badge notification
- Toggle automatic initialization
- Maximum amount of retries
- Retry Delay (the amount of delay between each retry attempt)
🧠 Example
local AchievementService = require(game.ReplicatedStorage.AchievementService)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
--[[
You can use :Award() using the BadgeName or the BadgeId
]]
AchievementService:Award(player, "Welcome")
AchievementService:Award(player, 123456789)
end)
end)
📜 Update Log
v1.03 - November 29th, 2024 (Current)
- Internal Recovery Module Added
- Introduced
:SafeCall()
function to handle retries when a function fails. - The
SafeCall
function is now used within theAchievementService
module for more resilient function calls.
- Introduced
- New Variables
-
MaxRetryLimit
- Controls the maximum number of retry attempts (default is 5).
-
RetryDelay
- Defines the delay between retry attempts (default is 1 second).
-
- Code Documentation Improvements
- More comments have been added throughout the code to increase legibility and clarify the functionality for developers
-
achievementsService.Defaults
Table- Default values for configurable variables are now stored in the
Defaults
table for easier management.
- Default values for configurable variables are now stored in the
- Initialization Enhancements
-
AutoInitialize
variable- Determines whether the module initializes automatically on startup or if developers should initialize it manually.
- Developers can now call
AchievementService.init()
again to retry initialization if the first attempt fails. (It is recommended to disableAutoInitialize
and handle initialization yourself if you choose to do this.) - Improved checks during initialization for a smoother startup process.
-
- Removed Redundancy
- Removed the redundant
achievementService.Timeout
variable and more for cleaner and more efficient code.
- Removed the redundant
- New IntValue Dependency (
Duration
)- Added an
IntValue
calledDuration
inside each AnimationStyle folder. This new value can be used to configure the duration of animations.
- Added an
This update improves both the robustness and flexibility of the AchievementService
module, providing developers with more control over initialization and retry logic.
Silent Update - November 30th, 2024
v1.02 - November 28th, 2024
- Improved Code Redundancy
- Optimized and streamlined the code for better efficiency and maintainability
- Self-Initialization
- The module now automatically self-initializes without the need for the user to manually call
.init()
. (Courtesy of @TheRealANDRO)
- The module now automatically self-initializes without the need for the user to manually call
- Fixed 100 Badge Limit
- The module now handles badge pagination, ensuring that all badges are retrieved from the Roblox API, even if there are more than 100.
- Support for BadgeName and BadgeId
- You can now use either
BadgeName
orBadgeId
when using:Award()
, providing more flexibility.
- You can now use either
- Fixed Badge Description Being Nil
- Addressed an issue where badge descriptions were sometimes returned as nil.
- Removed Debris
- Removed the use of Debris service. (Courtesy of @Abcreator)
- Achievement Queue Fix
- Fixed issues with the achievement queue that could prevent badges from being awarded correctly.
- Added Badge Availability Check
- Added a check to ensure that the badge being awarded is not disabled. (Courtesy of @Abcreator)
- Toggle for Default Badge Notification
- You can now enable or disable the Roblox default badge notification. (Courtesy of @Abcreator)
This update contains several fixes and new features, improving both flexibility and functionality! Thanks to all contributors for their valuable input!
v1.01 - November 28th, 2024
- New Variables Added:
-
achievementService.UseHTTPService
- Determines if AchievementService should fetch BadgeIds and BadgeInfo using HTTPService.
- Default:
true
-
achievementService.BadgeIdFallback
- Specifies whether to fall back on achievementService.BadgeIds if HTTPService fails.
- Default:
false
-
achievementService.BadgeIds
- An optional table for manually specifying BadgeIds when not using HTTPService.
- Default:
{}
(empty table)
-
This update introduces configuration options to accommodate different use cases. For example, if you want to avoid relying on HTTPService, you can set achievementService.UseHTTPService
to false
and insert BadgeIds into the achievementService.BadgeIds
table manually. Additionally, achievementService.BadgeIdFallback
ensures that the system switches to using local BadgeIds when HTTPService encounters issues. Please note that the BadgeId method may take longer to fetch BadgeInfo.
v1.00 - November 28th, 2024
- Released
📄 License
AchievementService is under the MIT license.View license
MIT License
Copyright (c) 2024 funtmaster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
🌐 Miscellaneous
- Developed and created by @FuntMaster.
- Hall of Contributors:
@TheRealANDRO, @Abcreator - v1.04 plans
- As of right now, there are no plans for v1.04. Have a suggestion? Let me know!
- One thing to note is that AchievementService uses RoProxy to access Roblox Badge APIs. Although rare, I cannot control any downtime or slowdown that occur with this proxy. If you’d like to use an alternative, you can configure the method used to retrieve the badges (refer to the Installation Guide) or use your own self-hosted proxy.
- Lastly, please feel free to let me know of any bugs, issues, suggestions that you have!
P.S. this is my first time making a community resource!