Help with badge script

Basically what I’m trying to accomplish is to give the player a badge once they reach level 10.
I wrote the code and i don’t see any errors in it, and the output agrees.
This is a script in ServerScriptService.

local checkpoints = workspace:WaitForChild("Checkpoints")

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

	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Value = 1
	stage.Parent = leaderstats

	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		wait()
		char:MoveTo(checkpoints[stage.Value].Position)

		hum.Touched:Connect(function(hit)
			if hit.Parent == checkpoints then
				if tonumber(hit.Name) == stage.Value + 1 then
					stage.Value = stage.Value + 1
--------------------------------------------------END OF STAGE SCRIPT----------------------------------------------------
					--------------------------------------------------START OF BADGE SCRIPT--------------------------------------------------	
					
					local players = game:GetService("Players")
					local badgeService = game:GetService("BadgeService")

					players.PlayerAdded:Connect(function(player)
						local leaderstats = player:WaitForChild("leaderstats")
						local stage = leaderstats:WaitForChild("Stage")

						stage.Changed:Connect(function(newValue)
							if newValue >= 10 then
								badgeService:AwardBadge(player.UserId, 2142498839)
							end
						end)
					end)
				end
			end
		end)
	end)
end)

Here is an example of how to use Badge Service. In this script we simply check if the player has ownership of a badge and if they don’t then we award them with our select badge. I haven’t tested this however I assume it will give you a idea of how Badge Service functions.

game.Players.PlayerAdded:Connect(function(Player)
	local BADGE_ID = 1
	if game:GetService("BadgeService"):UserHasBadgeAsync(Player.UserId, BADGE_ID) then
		return
			else
		game:GetService("BadgeService"):AwardBadge(Player.UserId, BADGE_ID)
		end
end)
1 Like

did this:

local players = game:GetService("Players")
					local badgeService = game:GetService("BadgeService")
					
					game.Players.PlayerAdded:Connect(function(Player)
						local BADGE_ID = 2142498839
						if game:GetService("BadgeService"):UserHasBadgeAsync(Player.UserId, BADGE_ID) then
							return
						else
							game:GetService("BadgeService"):AwardBadge(Player.UserId, BADGE_ID)
						end
					end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.