Badge doesn't get rewarded to player

When it time to reward the player with the badge the console says this…
image
or it just doesn’t give the playe the badge

This is the script that goes with it

Local script

local badgeData = game.ReplicatedStorage.Components.Objects.ChristmasEvent:FindFirstChild("BadgeData")


badgeData:FireServer(player.UserId)

Script in serverscriptstorage

local BadgeService = game:GetService("BadgeService")
local badgeId = 456989618962327

local function awardBadge(player, badgeId)
	local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
	if success then
		if badgeInfo.IsEnabled then
			local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, player.UserId, badgeId)
			if not awarded then
				warn("Error while awarding badge:", errorMessage)
			end
		end
	else
		warn("Error while fetching badge info!")
	end
end

Do anyone know how I would fix this + why its showing that error

I think that just means you can only get the badge while testing it on Roblox

I think it’s because you can’t get them in studio. And why is the script in server storage??

Then where would it go? And how would you link the two script together

Oh hi Jelly!

Did you fire the remote event?

Put it maybe in server script service

Do I need to put anything in the brackets ?

BadgeData:FireServer()

I am currently testing your code. It should be the player.UserId

in which script, the local or server one

Local script as you are sending the information from local to server so the server can give out the badge.

One question are you awarding the badge or checking it cause in the script i don’t see anywhere that you are awarding it.

awarding the badge to the player

Server code:

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")

local remote = RS:WaitForChild("RemoteEvent")
local badgeId = 1606426293935544

remote.OnServerEvent:Connect(function(player)
	if not BadgeService:UserHasBadgeAsync(player.UserId, badgeId) then
		BadgeService:AwardBadge(player.UserId, badgeId)
	end	
end)

Local code:

local RS = game:GetService("ReplicatedStorage")
local remote = RS:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	remote:FireServer(player)
end)

So i would do something like this just change the event etc. and it should work.

This is how i usually do it.

It’s just fireserver() the player value is automatically always passed through

1 Like

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