(SOLVED)How to make a badge be awarded once you get lets say 100 points on a leaderstat

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 be awarded once a player reaches a number on the leaderstat board

  2. What’s the problem? Don’t know how have been looking for days but cant find anything

  3. What solutions have you tried so far? i looked on the dev forum and youtube and reddit for hours and didn’t find anything about this subject

Does anybody know where I can find stuff about this and get a tutorial from like a yt video becuase I cannot find anything i want it for my game so then the player can have more achiveable things (more things to do) I’m hoping anybody here reading this knows where I can find a tutorial or something like that i cant code it myself since i just started developing and know nothing

2 Likes

You can use the Changed event to detect changes in the IntValue’s value and AwardBadge to award the badge if the new value is 100

Example

local BadgeService = game:GetService("BadgeService")

Value.Changed:Connect(function(newValue)
	if newValue == 100 then
		BadgeService:AwardBadge(your badge id)
	end	
end)
4 Likes

Thank you i will try something like this

1 Like

Do you know how i would connect the leaderstat to the script?

Put it in the same code where your leaderstats is made and change some stuff around

ok i will put it in leader stats

Sorry for asking so many questions but do you know how I can make it so even if you surpassed the value it still awards it to you like a greater than thing and I think I’m changing this to the wrong thing
image

Value in my example should be the variable that contains the IntValue that you want to check

And if you want to make it give if the value is greater than your value of 100, use > instead of ==

Should i put an intvalue into the leaderstats and what should i set the intvalue to

If you don’t alreayd have a leaderstats for points, you need to do that beforehand. The IntValue I’m referring to is where you store your points that you later want to check for badge awarding

1 Like

im really sorry i keep asking but i think im doing it wrong

local BadgeService = game:GetService("BadgeService")
local badgeID1 = 2127937880
local Player = game:GetService("Players")

DataStore.Changed:Connect(function(aliveTime)
	if aliveTime > 49 then
		if not BadgeService:UserHasBadge(Player.UserId, badgeID1) then
			BadgeService:AwardBadge(2127937880)
		end
		
end)

yes i have a leaderstat with data storage
ive been trying to mess around with it to get it to work

You have the logic correct, though what is DataStore? The code I was talking about should be in the same script where you create the leaderstats, so you already ahve the Intvalue to check stored in a variable, which it allows for easy access to its Changed event

ill just send my whole script

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr

	local aliveTime = Instance.new("IntValue")
	aliveTime.Name = "Time Alive"
	aliveTime.Parent = leaderstats

	local bestTime = Instance.new("IntValue")
	bestTime.Name = "Best Time"
	bestTime.Parent = leaderstats

	local data

	local success, message = pcall(function()
		data = DataStore:GetAsync(plr.UserId .. "-Data")
	end)

	if success then
		if data then
			bestTime.Value = data
		end
	else
		warn(message)
		plr:Kick("Error while retrieving your data.")
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local data = plr.leaderstats["Best Time"].Value

	local success, message = pcall(function()
		DataStore:SetAsync(plr.UserId .. "-Data", data)
	end)

	if not success then
		warn(message)
	end
end)

local BadgeService = game:GetService("BadgeService")
local badgeID1 = 2127937880
local Player = game:GetService("Players")

DataStore.Changed:Connect(function(aliveTime)
	if aliveTime > 49 then
		if not BadgeService:UserHasBadge(Player.UserId, badgeID1) then
			BadgeService:AwardBadge(2127937880)
		end
		
end)

its for a game with mazes and nextbots n stuff

Put the changed event code in the PlayerAdded event after the aliveTime.Parent line

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

local badgeID1 = 2127937880

Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr

	local aliveTime = Instance.new("IntValue")
	aliveTime.Name = "Time Alive"
	aliveTime.Parent = leaderstats
	
	aliveTime.Changed:Connect(function(newValue)
		if newValue > 49 then
			if not BadgeService:UserHasBadgeAsync(plr.UserId, badgeID1) then
				BadgeService:AwardBadge(plr.UserId, badgeID1)
			end	
		end
	end)

	local bestTime = Instance.new("IntValue")
	bestTime.Name = "Best Time"
	bestTime.Parent = leaderstats

	local data

	local success, message = pcall(function()
		data = DataStore:GetAsync(plr.UserId .. "-Data")
	end)

	if success then
		if data then
			bestTime.Value = data
		end
	else
		warn(message)
		plr:Kick("Error while retrieving your data.")
	end
end)

Players.PlayerRemoving:Connect(function(plr)
	local data = plr.leaderstats["Best Time"].Value

	local success, message = pcall(function()
		DataStore:SetAsync(plr.UserId .. "-Data", data)
	end)

	if not success then
		warn(message)
	end
end)

2 Likes

i think my brain is too tiny ive been looking at what your saying and the code for like 20 minutes idk

like this


?

I think if you use how I did it it should work since I think you copied your old version, which wont work cause you’re trying to the userid of the Players service

Edit since you edited: I think that’ll work

1 Like

i replaced the image i added some things i did try your script but it did not work

ima try this now also can you be awarded badges in roblox studio? cuz that might’ve been my problem