BADGE+
Badge+ is a plugin that can let you easily access badge templates that you will only need to change the id of! It contains multiple templates of badges and will always update with new ones! This is useful for developers who do not want to write a badge for every game they make and can access it with a click of a button!
I think it will be useful for developers who are just starting out and don’t know about it. And you will help them. And it looks nice even though you did it plugin as the 2nd.
Good work!
This plugin looks very helpful! It’d be cool if you added a way to insert a template with one of the game’s badges.
How do I do that?
This is a difficult concept if you don’t have API experience, so I made this code to help if you like the idea. This code works as-is and can be added to the plugin. This can also be used beyond the plugin for curious people, hence this reply.
-- Variables:
local badges = {}
local httpService = game:GetService("HttpService")
local placeId = game.PlaceId
-- Check to see if place is published?
if placeId ~= 0 then
-- Attempt to make a http request to my roblox proxy
local success,response = pcall(function()
return httpService:JSONDecode(httpService:GetAsync(("https://rbx-badge.glitch.me/game/%s"):format(placeId)))
end)
-- See if it responded and has a valid response
if success and response then
if response.success then -- Everything went well!
badges = response.badges
else -- Something went wrong on the server
warn("Error fetching badges internally - " .. response.message)
end
else -- Something errored on Roblox's side
warn("Error getting badges - " .. response)
end
end
for _,badge in pairs(badges) do --> Loop through badges
print(badge.name) --> Badge name
print(badge.id) --> Badge id
print(badge.description) --> Badge description
print(badge.imageId) --> Badge image
print(badge.enabled) --> Is it enabled for use?
end
I also examined some of the code and I found a way to shorten your BadgeInserter module.
Click
Notes:
It’s good practice to use ‘game:GetService’ instead of directly stating the service name
You can use dictionaries to shorten this like below
local BadgeInserter = {}
local BadgesFolder = script.Parent.Parent.Parent.Resources.Badges
function BadgeInserter.WelcomeBadge()
local WelcomeBadgeScript = BadgesFolder.WelcomeBadge
local clone = WelcomeBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Welcome Badge has been inserted.")
game.ServerScriptService.WelcomeBadge.Disabled = false
end
function BadgeInserter.TimeBadge()
local TimeBadgeScript = BadgesFolder.TimeBadge
local clone = TimeBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Time Badge has been inserted.")
game.ServerScriptService.TimeBadge.Disabled = false
end
function BadgeInserter.PromptBadge()
local PromptBadgeScript = BadgesFolder.PromptBadge
local clone = PromptBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Prompt Badge has been inserted.")
game.ServerScriptService.PromptBadge.Disabled = false
end
function BadgeInserter.PartBadge()
local PartBadgeScript = BadgesFolder.PartBadge
local clone = PartBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Part Badge has been inserted.")
game.ServerScriptService.PartBadge.Disabled = false
end
function BadgeInserter.GroupBadge()
local GroupBadgeScript = BadgesFolder.GroupBadge
local clone = GroupBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Group Badge has been inserted.")
game.ServerScriptService.GroupBadge.Disabled = false
end
function BadgeInserter.GamepassBadge()
local GamepassBadgeScript = BadgesFolder.GamepassBadge
local clone = GamepassBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Gamepass Badge has been inserted.")
game.ServerScriptService.GamepassBadge.Disabled = false
end
function BadgeInserter.DiedBadge()
local DiedBadgeScript = BadgesFolder.DiedBadge
local clone = DiedBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Died Badge has been inserted.")
game.ServerScriptService.DiedBadge.Disabled = false
end
function BadgeInserter.CreatorBadge()
local CreatorBadgeScript = BadgesFolder.CreatorBadge
local clone = CreatorBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Creator Badge has been inserted.")
game.ServerScriptService.CreatorBadge.Disabled = false
end
function BadgeInserter.ClickBadge()
local ClickBadgeScript = BadgesFolder.ClickBadge
local clone = ClickBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Click Badge has been inserted.")
game.ServerScriptService.ClickBadge.Disabled = false
end
function BadgeInserter.ChatBadge()
local ChatBadgeScript = BadgesFolder.ChatBadge
local clone = ChatBadgeScript:Clone()
clone.Parent = game.ServerScriptService
print("[BADGES+] Chat Badge has been inserted.")
game.ServerScriptService.ChatBadge.Disabled = false
end
return BadgeInserter
to
local BadgeInserter = {}
local ServerScriptService = game:GetService("ServerScriptService")
local BadgesFolder = script.Parent.Parent.Parent.Resources.Badges
local BadgeTypes = {
["WelcomeBadge"] = BadgesFolder.WelcomeBadge,
["TimeBadge"] = BadgesFolder.TimeBadge,
["PromptBadge"] = BadgesFolder.PromptBadge,
["PartBadge"] = BadgesFolder.PartBadge,
["GroupBadge"] = BadgesFolder.GroupBadge,
["GamepassBadge"] = BadgesFolder.GamepassBadge,
["DiedBadge"] = BadgesFolder.DiedBadge,
["ClickBadge"] = BadgesFolder.ClickBadge,
["CreatorBadge"] = BadgesFolder.CreatorBadge,
["ChatBadge"] = BadgesFolder.ChatBadge
}
function Insert(Name,Badge)
local clone = Badge:Clone()
clone.Parent = ServerScriptService
clone.Disabled = false
print(("[\"BADGES+\"] %s Badge has been inserted."):format(Name:split("Badge")[1]))
end
for name,badge in pairs(BadgeTypes) do
BadgeInserter[name] = function()
Insert(name,badge)
end
end
return BadgeInserter
You could even further shorten it with :GetChildren(), but I’ll leave that up to you.
Thank you so much for the feedback and help with very detailed messages! You are going to be a big help! I am happy this is helpful for people as this is one of my first ever plugins!
Moving into the template idea I think I will try my best to implement that when I am on pc, it would help a lot for there to be templates!
For your improvement o generally put them into separate functions because in the main script I called them when they clicked a button, would this improvement still work with that?
Sorry for annoying you but now that I am on PC I see your api code more! Could you possibly tell me how to implement this into my plugin? What I mean is what script does it have to be in and such
function OnChild(child)
if child:IsA("TextButton") then -- make sure it's actually a text button
SoundModule.CompleteSound() -- play your sound
BadgeInserter[child.Name]() -- call the badge inserter with the button's name (ex: if the button is named TestBadge it'll call .TestBadge() on your BadgeInserter)
end
end
for _,child in pairs(BadgesListFrame:GetChildren()) do -- check all the buttons in the frame
task.spawn(OnChild,child)
end
BadgesListFrame.ChildAdded:Connect(OnChild) -- any buttons added to the frame also will also do the same
You can do that with a lot, :GetChildren() is like literally god lol
(that should work but I haven’t tested it)
function OnChild(child)
if child:IsA("TextButton") then -- make sure it's actually a text button
SoundModule.CompleteSound() -- play your sound
child.MouseButton1Click:Connect(BadgeInserter[child.Name]) -- call the badge inserter with the button's name (ex: if the button is named TestBadge it'll call .TestBadge() on your BadgeInserter)
end
end
for _,child in pairs(BadgesListFrame:GetChildren()) do -- check all the buttons in the frame
task.spawn(OnChild,child)
end
BadgesListFrame.ChildAdded:Connect(OnChild) -- any buttons added to the frame also will also do the same
That works thank you so much! Also its ok we all make mistakes lol. Now my plugin can be shorter and easier to learn for other people when they view its source!
Pushed out a temporary fix, I will try making the frames draggable over the weekend, thank you so much for actually using my plugin I didn’t expect people to use this.