I am doing stuff with awarding badges and was wondering how to award a badge to the person who clicked a text button? I am thinking of using a script because I'm pretty sure that's what you use with badges. Is there any way I can do this without using remote events or do I have to use them?
How to tell which player clicked a button?
2 answers
You can use it, or don't use it. There's no way to say do you need to use it. If you use it correctly, the script also works.
I think you should don't need to use RemoteEvent. RemoveEvent is a thing that's let the server's player knows, that called: FireServer().
You must put this script into the StarterGui > Button. Also, you must do it a script. Not a LocalScript or ModuleScript.
Let get right into the script.
local BadgeID = (000000000)
This is your Badge ID. It can be founded in 'View > Show > Game Explorer'. You must public the game to found your badge inside the 'Game Explorer > Badges'. Right-click on the badge and select 'Copy ID to clipboard'.
local BadgeService = game:GetService("BadgeService")
BadgeService is a 'service' that gives you to award badge to the people, but this wasn't work in Roblox Studio, that's why I tell you public the game.
local button = game.StarterGui.Button
Important, you must change the 'Button' to your button's name.
function onClicked(player)
if not BadgeService:UserHasBadgeAsync(player.UserId, badgeID) then
BadgeService:AwardBadge(player.UserId, badgeID)
The first line, script creates a function that on clicked. Second, If the player doesn't get the badge yet... Third, the BadgeService will award the badge to you.
Last line:
button.Mouse1Down:Connect(onClicked)
Finally, this line tells us when the player 'MouseButton1Click', simply called clicked, then connects with the function 'onClicked'. Is this like connecting Redstone? xD
Ok, the entire script :
local badgeID = (000000000)
local badgeService = game:GetService("BadgeService")
local button = game.StarterGui.Button
function onClicked(player)
if not badgeService:UserHasBadgeAsync(player.UserId, badgeID) then
badgeService:AwardBadge(player.UserId, badgeID)
end
end
button.MouseButton1Click:Connect(onClicked)
Hope I helped, if you have any questions, comment below! :D
Thanks for reading, have a nice day and bye!
16 comments
My grammar is so bad xD Rip my all English teacher 2019-2019
I like how you cut the script in the parts, but one part you forgot the ends.. lol
This helps a lot, but is it possible to make it invisible (with a script) after you click it?
Yep. I dare you to try yourself with MouseButton1Down and Visible >:) If you don't know how to do, tell me so i'll tell you tha answer >:)
Good lack :)
so would I have to do something like, player.StarterGui.ScreenGui.Frame.TextButton.Visible = true, I'm a bit confused about how I will do it only locally.
Oh, you can do Player:WaitForChild("PlayerGui").ScreenGui.Frame.TextButton.Visible.. Maybe try to do this..?
cool, I will!
The visibility thing worked but it isn't awarding me my badge? I deleted it from my inventory but it still didn't work? Thanks so much though for helping me, I have been searching for weeks!
Oh wait,wait. I put this script into the ServerScriptService :V I forget to tell u
Yea, I did that
nvm, the visibility thing doesn't work either, this is the error
BadgeId '2124489619' is not of type Badge. Please use MarketplaceService:PlayerOwnsAsset instead.
also is it possible to do badge stuff in a local script?
MarketplaceService:PlayerOwnsAsset was a type of function that give peoples buy Gamepasses.
No. LocalScript is impossible to do award badge, if you figured out the way to use LocalScript and award badge to other then teach me :V
k, I kinda answered some of my questions: 1. No it isn't possible in a local script 2. The badge script I think works, the thing that doesn't work is the button press, there is a problem with it to do with the script working with a client side thing.
Script I got from a channel to test if the badge works (it does)
game.Players.PlayerAdded:Connect(function(plr)
if plr then
game:GetService("BadgeService"):AwardBadge(plr.userId, 2124489619)
end
end)
My current badge button script (I changed the "if not" to see if it worked because I have had previous encounters where "not" has not worked but it didn't change anything.
local badgeID = 2124489619
local badgeService = game:GetService("BadgeService")
local button = game.StarterGui.Frame4.Noob
button.MouseButton1Click:Connect(function(player)
if badgeService:UserHasBadge(player.UserId, badgeID) then
else
badgeService:AwardBadge(player.UserId, badgeID)
end
end)
2 comments
Its same. First script is the people joined then give the player badge. Second is make the local BadgeId's brackets remove. Its same, keep going! Great job dude :D
For some reason though the second script doesn't give the badge?
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Do you have a script?