Badge doesn't award when script is ran

Hey! I’ve been trying to award a badge and no matter what I do the badge doesn’t award. I’m pretty confused on what’s happening and wonder what you all think.

When the remote event is fired, the script itself runs as info on the badge is printed, and the “Christmas Badge Awarded” is also printed. The badge also has “isEnabled = true” in the info. I’ve also tried looking at other topic’s solutions, none have worked.

Completely stuck on ideas, wondering what you all think.
Thanks in advance!


local function christmas()
	local player3 = game:GetService("Players"):FindFirstChildWhichIsA("Player")
	local userId4 = player3.UserId

	print(BadgeService:GetBadgeInfoAsync(2129845263))

	BadgeService:AwardBadge(player3.UserId, 2129845263)
	
	print("Christmas Badge Awarded")

end   

game.ReplicatedStorage.ChristmasEvent.OnServerEvent:Connect(christmas)

are you trying to make it so all players get the badge?

Game is a single-player game, it’s just a bit easier on my end to get the player that way. Should have clarified, my bad!

The issue was that the script was missing the parameters for the AwardBadge function. The AwardBadge function requires two parameters, the userId and the badgeId. In this case, the userId was stored in a variable called userId4, but this variable was never passed to the AwardBadge function. We also need to pass the badgeId, which in this case is 2129845263.

To fix the issue, we need to update the AwardBadge function to include both the userId and the badgeId. The updated script should look like this:

local function christmas()
	local player3 = game:GetService("Players"):FindFirstChildWhichIsA("Player")
	local userId4 = player3.UserId

	print(BadgeService:GetBadgeInfoAsync(2129845263))

	BadgeService:AwardBadge(userId4, 2129845263)
	
	print("Christmas Badge Awarded")

end   

game.ReplicatedStorage.ChristmasEvent.OnServerEvent:Connect(christmas)

Isn’t replacing the “player3.UserId” I used in the parameters with “userId4” the same thing as the “player3.UserId” itself? I might be wrong here since I’m not the best with lua.

Anyway, I tried this and it still didn’t award the badge.

No, it isn’t the same thing. You need to pass in the actual user ID for the player you want to award the badge to. The userId4 variable is just a placeholder for the user ID of the player you want to award the badge to.

Oh my bad. Anyway, I’m not too sure where to go forward from here as I’ve already tried so many things.

But have you tried the script I gave you already? If you did and an error popped up, please send it and I will try to modify the script.

Yeah I tried the script earlier, but no error popped up. I can send you a photo of the output between the two prints present in the script however.
image

Maybe you can’t test them in studio, try to test them in-game so like launch the game from ROBLOX and not from ROBLOX Studio.

1 Like

It worked now? Weird. Thank you so much for the help, the badge awarded now despite the fact I tested it from the player around half an hour ago.

1 Like

Yeah no problem! ROBLOX Studio does not support badges, however I just found that out!

1 Like

I remember being awarded badges in Studio though, maybe I remember wrong? Anyway, thank you so much again. It’s appreciated a lot.

I think it didn’t award because it is a group game.

That does not matter if it is a group game, as you can see the badges on other group games like SCP: Roleplay are stll getting awarded to the player.

No I mean it doesn’t award in studio if its from a group.

Oh yeah, it in general doesn’t award in studio. I believe to get awarded in studio you need to turn on HTTP Requests.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.