How Give a Badge By Clicking a GUI Button?

Hello, So I want to give to an player a badge if they click a TextButton

Anyone know how to do this? I tried in various ways but it doesn’t work

4 Likes

You need to use a Remote Event to use BadgeService. You can’t give a badge to a player locally.

Hi, Thank you for answering.

I had come to this far enough, I just don’t know what to write on the serverscript,
how do you I get the userid with a serverscript?

Kinda like a free badge? Well you’d probably need to set this up using RemoteEvents (Which is basically 1-way transportation from the client-server/server-client)

  • Cause of this, it needs to be replicated across both sides which is why we’ll put it inside ReplicatedStorage

The reason why we wanna set it up on the server is cause the AwardBadge function can only be rewarded to the server’s side:

So say we want to implement a LocalScript parented inside our TextButton, we can detect for when the Button gets clicked by using the MouseButton1Down Event:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local TextButton = script.Parent

TextButton.MouseButton1Down:Connect(function()
    Event:FireServer()
end)

The FireServer() function will pretty much, fire from the client side to the server side, and we can detect this “fired” function by inserting a Server Script

The Server Script should belong in ServerScriptService since it’ll be secured & on the server-side:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local BadgeService = game:GetService("BadgeService")
local BadgeID = 0000000

Event.OnServerEvent:Connect(function(Player)
    BadgeService:AwardBadge(Player.UserId, BadgeID)
end)

The first parameter of an OnServerEvent Event would always be the Player that fired it from the client side, and then we can get the Player’s ID to award our badge that way!

20 Likes

Really useful, Thank you very much!

2 Likes