Finding if a Value is over 47, Give ALL players a badge

I want to see if a value is over 47, give all players in the server a badge. I just don’t know how to do it lo I don’t know much about scripting so pls help (I didn’t find this anywhere so yeah)
Heres some example code if u wana finish it lo

if diff.Value >= 47 then
	
end
local badgeService = game:GetService("BadgeService")

local function giveBadgeToAllPlayers(someBadgeID)
for _, p in ipairs(game.Players:GetPlayers()) do
pcall(function() badgeService:AwardBadge(p.UserId, someBadgeID) end)
end
end

There are multiple videos on how to make badges on YouTube, but here is one that I’d recommend:

You could also check out Roblox’s API, that has a built in tutorial at the bottom, on the DevHub: BadgeService

The documentation website is mostly the same as the DevHub, but is more recent. It is in beta however. Here is the badges api on there: BadgeService | Roblox Creator Documentation

So do I replace someBadgeId with the badge id? (on both occasions)

Thanks I’ll check them out later : D

You’d just have to execute the function with a specified badge ID to give to all the players in the game, like so:

giveBadgeToAllPlayers(badge_ID_goes_here)
1 Like

There’s a better way to do this

local BadgeServ = game:GetService("BadgeService")
local Value --Wherever the value is
local GiveBadge = workspace.GiveBadge
local BadgeId = 1234567890

Value.Changed:Connect(function(v)
	GiveBadge.Value = v > 47
end)

GiveBadge.Changed:Connect(function(BadgeGiven)
	if BadgeGiven then
		for _, v in pairs(game.Players:GetPlayers()) do
			if v.Character and v.Character:FindFirstChild("Humanoid") then
				BadgeServ:AwardBadge(v.UserId, BadgeId)
			end
		end
	end
end)