How can i make a gui that gives a badge?

I want to make a script that gives you a badge when a code (that you type in a box) is right.
I have tryed it but the Output just says " Sorry, badges can only be awarded by Roblox game servers"

1 Like

This is the sign that you should probably test this in the actual game rather than testing it in studio. Also try this using an alt to see if you get the badge.

I would also want to see the entire script you have written for this, since there could other problems we might have missed and could help you with it.

1 Like

Code :

while true do
	wait(0.5)
	if CodeText.Text == "Code" then
		S1:Play()
		local id = 2124639076
		print("Awarding BadgeID: " .. id .. " to UserID: " .. game.Players.LocalPlayer.userId)
		local b = game:GetService("BadgeService")
		b:AwardBadge(game.Players.LocalPlayer.userId, id)
	end
end

I tested it in a game. It still says the same thing

Is this a script for a TextBox object? If so, then using while true do may not be the best option, since you have it check for the text for more times than it actually needs to. Instead, a smarter way would be using FocusLost event, which fires when the player enters the text. If you want more information, I recommending reading here:

Also, I recommend avoiding names like b or S1, since it is much harder to guess what is being written here. Instead, I recommend using names that are short but descriptive and clear, like badgeService instead of b.

I just realized that this script is most likely written in a LocalScript, and, well…

You need to write a Remove Event to communicate from the LocalScript to a ServerScript, which will reward the player with the badge.

Badges must be awarded through the Server. It even said so in the Output. In your case, I’d create a RemoteEvent and fire it to the server, then award it there. You should some more research next time.

3 Likes