Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to give players a badge upon reaching a certain amount of points/score?

I am making a leaderboard for the number of times people ride roller coasters in my game, and I am trying to add a way to give players badges when they reach a certain level. The levels I am going to add are 50, 100, 200, 300, but I can't even get the first one to work.

Code:

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

local Coasters = Instance.new("IntValue")
Coasters.Name = "Coasters"
Coasters.Parent = leaderstats


local BadgeService = game:GetService("BadgeService")
local badgeid = --BadgeID Here

	Coasters:GetPropertyChangedSignal("Value"):Connect(function(value)
		if value >= 50 then
		BadgeService:AwardBadge(badgeid)
	
	end
	end)
	end)

2 comments

0

I am also beginner and I dont know if this is case but this will award badge after it becomes 51 because of >=

0

No because of >= means if it's 50 or above 50 then it's good

2 answers

✓ Accepted answer

I immediately saw the problem, actually 2 problems!

  1. You're are not doing a while loop, otherwise it's gonna only check once and not ever again!
  2. You did value in the parameters no need for that since you can already check the Coasters Value!.

Here's your new code:

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

	local Coasters = Instance.new("IntValue")
	Coasters.Name = "Coasters"
	Coasters.Value = 0
	Coasters.Parent = leaderstats

	local BadgeService = game:GetService("BadgeService")
	local badgeid = 0
	
	coroutine.resume(coroutine.create(function() -- Corountine loop so we don't disturb code below it!
		while wait() do
			Coasters:GetPropertyChangedSignal("Value"):Connect(function()
				if Coasters.Value >= 50 then
					BadgeService:AwardBadge(badgeid)
				end
			end)
		end
	end))
end)

2 comments

0

Thank you very much!

0

Np

hey you! have you ever heard of enes? if you are in trouble, better call enes!

This discussion is preserved as it was. New answers, comments, and votes are closed.