Badge Service probably isn't working

I’m trying to make something that when a player reaches 250 candies, they get a badge but it isn’t working right now and I don’t know how to fix it!

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

	local Slaps = Instance.new("IntValue", leaderstats)
	Slaps.Name = "Slaps"
	Slaps.Value = 1000000

	local Glove = Instance.new("StringValue", leaderstats)
	Glove.Name = "Glove"
	Glove.Value = "Default"
	
	local candyz = Instance.new("IntValue", player)
	candyz.Name = "Candy"
	candyz.Value = 0
	
	if candyz.Value >= 1 then
		print(player.Name.. "has got 250 candy!")
		game:GetService("BadgeService"):AwardBadge(player.UserId, 1302136441780953)
	end
end)

Please help me try to fix the badge.

What do you mean it isn’t working right now?
Does the print(player.Name.."has got 250 candy!") output?
Are you testing it in game or in studio?

  1. It isn’t working for me right now I think.
  2. It doesn’t appear in output.
  3. I tested it in both studio and ingame.

image
The issue is that you are setting the value to 0, then immediately checking if it’s more than 1 (which is always going to be false).

Where are you changing the amount of candy?

I’m changing it using the collectibles.

I’m just going to assume that you are changing the value in it at some point.

Try replacing

if candyz.Value >= 1 then
		print(player.Name.. "has got 250 candy!")
		game:GetService("BadgeService"):AwardBadge(player.UserId, 1302136441780953)
	end

with

candyz.Changed:Connect(function()
    if candyz.Value >= 1 then
		print(player.Name.. "has got 250 candy!")
		game:GetService("BadgeService"):AwardBadge(player.UserId, 1302136441780953)
	end
end)

Thank you so much for helping me!

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