First time join badge script not working

yea it works for you but it wont work for them

ohh didnt notice my bad my bad

im just gonna wait until they send the output so i can figure it out

Ej do u consider urself a very good programmer? if so i posted about an issue i have and I kinda need help as i got no clue how to fix it

ok ill go take a look at it right now

you dont have to check if the badge is enabled since its already pcalled

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

local BADGE_ID = 2129936701

local function awardBadge(player, badgeId)
	local awardSuccess, result = pcall(function()
		return BadgeService:AwardBadge(player.UserId, badgeId)
	end)

	if not awardSuccess then
		-- the AwardBadge function threw an error
		warn("Error while awarding badge:", result)
	elseif not result then
		-- the AwardBadge function did not award a badge
		warn("Failed to award badge.")
	end
end

local function onPlayerAdded(player)
	awardBadge(player, BADGE_ID)
end

Players.PlayerAdded:Connect(onPlayerAdded)
 15:42:13.942  Failed to award badge.  -  Server - BadgeService:25

try changing badgeId to BADGE_ID

Did not work.

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

local BADGE_ID = 2129936701

local function awardBadge(player, BADGE_ID)
	-- Fetch badge information
	local success, badgeInfo = pcall(function()
		return BadgeService:GetBadgeInfoAsync(BADGE_ID)
	end)

	if success then
		-- Confirm that badge can be awarded
		if badgeInfo.IsEnabled then
			-- Award badge
			local awardSuccess, result = pcall(function()
				return BadgeService:AwardBadge(player.UserId, BADGE_ID)
			end)

			if not awardSuccess then
				-- the AwardBadge function threw an error
				warn("Error while awarding badge:", result)
			elseif not result then
				-- the AwardBadge function did not award a badge
				warn("Failed to award badge.")
			end
		end
	else
		warn("Error while fetching badge info: " .. badgeInfo)
	end
end

local function onPlayerAdded(player)
	awardBadge(player, BADGE_ID)
end

Players.PlayerAdded:Connect(onPlayerAdded)

Does the badge ID that you are attempting to award belong to a badge that you made yourself? You can’t award badges that don’t belong to the game you are trying to award it in.

Edit: You can create badges for free by going to the game settings in studio.

The badge is linked to the game

Have you tried using the script in-game. You might just not be able to get the badge in studio. (For clarification, I mean publishing, then testing the game in a live game session.)

I have tried in game but the same error occurs.

If the error is always “Failed to award badge.” then my best guess is that you already own the badge, or something is internally wrong which would be the last possibility.

Perhaps delete the

local function onPlayerAdded(player)
	awardBadge(player, BADGE_ID)
end

And from the player added directly try to launch the awardBadge function.

Also remove from both functions BADGE_ID in the () beacuse the error seems to not get the badge so that could be the problem try sending the player badge itself

Dont do that man, the variable in the function and the variable in the script will overlap

Also if the error still occurs after what i sayed its probably the fact that you either have the wrong id or you already have the badge

Ok, I’ll try all the things you mentioned.

Figured it all out, thank you everyone.

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