First time join badge script not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want to make a badge that people get for joining my game for the first time.

  2. What is the issue?
    In game, on the developer console, it says “Failed to award badge”, the script has no errors and the badge is active

  3. What solutions have you tried so far?
    I have tried different methods of awarding the badge and checking but it doesn’t work.

My code, in ServerSciptService, the code is from BadgeService | Roblox Creator Documentation so I don’t understand why it doesn’t work, I did create my own script initially but it didn’t work so I tried Roblox’s own script.

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

local BADGE_ID = 2129936701

local function awardBadge(player, badgeId)
	-- Fetch badge information
	local success, badgeInfo = pcall(function()
		return BadgeService:GetBadgeInfoAsync(badgeId)
	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, 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
	else
		warn("Error while fetching badge info: " .. badgeInfo)
	end
end

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

Players.PlayerAdded:Connect(onPlayerAdded)

Any suggestions on what to do?

can you send the output please

that probably wont work for them because they have different variables

Hold ill put it properly for better visual

local BadgesService = {}

– SERVICES
local BadgeService = game:GetService(“BadgeService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

– EVENTS
local Network = ReplicatedStorage.Events:WaitForChild(“Network”)
local Update = ReplicatedStorage.Events:WaitForChild(“Update”)

– PLAYER VARIABLES
local StarterGui = game:GetService(“StarterGui”)
local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local PlayerGUI = Player:WaitForChild(“PlayerGui”)
local Client = PlayerGUI:WaitForChild(“Client”)

– VARIABLES
local BadgeContainer = script.Parent.Parent.BadgesFrame:WaitForChild(“Container”)
local Badges = {2130459377}

– FUNCTIONS
function BadgesService:CreateBadge(badgeId, state)
local badgeObj = script:WaitForChild(“BadgeObj”):Clone()
local success, result = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if not success then
return warn("[CLIENT] - Could not load badge!")
end
badgeObj.Name = result.Name
if state then
badgeObj.Title.Text = result.Name
badgeObj.Description.Text = result.Description
badgeObj.Info.State.Text = “Owned”
else
badgeObj.Title.Text = result.Name
badgeObj.Description.Text = result.Description
badgeObj.Info.State.Text = “Not Owned”
end
badgeObj.Parent = BadgeContainer
end

function BadgesService:LoadBadges()
for _, badgeID in pairs(Badges) do
if Network:InvokeServer(“Badge”, badgeID) then
BadgesService:CreateBadge(badgeID, true)
else
BadgesService:CreateBadge(badgeID, false)
end
end
end

– CONNECTIONS
BadgesService:LoadBadges()

return BadgesService

just change the badge ID ofcourse

there is more to it than that…

that script isnt gonna work for them because it has something to do with startergui but in their script it has nothing do with it

Well idk about more but this script works perfectly fine with me

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