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?
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?
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.
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!
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)