Scripting Help / Badge Award w Leaderstats

I have a script that should grant a badge when the player’s leaderstat reaches certain value.

print("Script started running.")

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

local badgeId1 = 4303832512527984   -- Badge ID for 100 seconds
local badgeId2 = 952021745612171    -- Badge ID for 1000 seconds
local badgeId3 = 1104558979106111   -- Badge ID for 10000 seconds

local function AwardBadge(player, badgeId)
	local success, result = pcall(function()
		badgeService:AwardBadge(player.UserId, badgeId)
	end)

	if success then
		print("Badge awarded to", player.Name, "with badge ID:", badgeId)
	else
		warn("Failed to award badge to", player.Name, "with badge ID:", badgeId, "Error:", result)
	end
end

local function CheckAndUpdateBadge(player, bestTime)
	if bestTime >= 100 then
		AwardBadge(player, badgeId1)
	end

	if bestTime >= 1000 then
		AwardBadge(player, badgeId2)
	end

	if bestTime >= 10000 then
		AwardBadge(player, badgeId3)
	end
end

local function OnBestTimeChanged(player, bestTime)
	print("Best Time for", player.Name, "changed to", bestTime)
	CheckAndUpdateBadge(player, bestTime)
end

local function OnCharacterAdded(character)
	local player = playerService:GetPlayerFromCharacter(character)
	if player then
		local leaderstats = character:FindFirstChild("leaderstats")
		if leaderstats then
			local bestTimeStat = leaderstats:FindFirstChild("Best Time")
			if bestTimeStat then
				bestTimeStat.Changed:Connect(function()
					OnBestTimeChanged(player, bestTimeStat.Value)
				end)
			end
		end
	end
end

playerService.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		OnCharacterAdded(character)
	end)

	local character = player.Character
	if character then
		OnCharacterAdded(character)
	end
end)

for _, player in ipairs(playerService:GetPlayers()) do
	local character = player.Character
	if character then
		OnCharacterAdded(character)
	end
end

However, the badge isn’t being awarded when someone reaches value equal or higher to 100, 1000 or 10000.

I think you messed this up. You should be getting leaderstats from the player.
If it still doesn’t work, does anything print normally?

Well, only the script running prints I think. I haven’t seen anything else print apart from that the last time i checked