Badge Not Granted At Currency Can Someone Help?

Still Struggling

The Code

This Code Opens A Trick Or Treat Door when you click a doorbell then you get candy
when you get 80 candy you get a badge.
badges are not being granted
anyone see the error ?

local ServerScriptService = game:GetService(“ServerScriptService”)
local RS = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)

local DataStore2 = require(5519945290) – This is the ID of you place

DataStore2.Combine(“DATA”, “Candies”)

local badges = game:GetService(“BadgeService”)

local FirstId = 2124857939-- ID of the Badge
local SecondId = 2124857941
local ThirdId = 2124857942

game.Players.PlayerAdded:Connect(function(player)

local CandyStore = DataStore2("Candies", player)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local CandiesVariable = Instance.new("IntValue", leaderstats)
CandiesVariable.Name = "Candy"



CandiesVariable.Value = CandyStore:Get(0) 

wait(1)

if CandyStore:Get() ~= nil then 
	print"Candies Exist in Data"
	CandiesVariable.Value = CandyStore:Get(CandiesVariable) 
else	
	print"Player had no Old Data"

	CandiesVariable:Set(0)	
end


local function CandyChanged(ChangedC) -- A vida 
	CandiesVariable.Value = CandyStore:Get(ChangedC)
	print"Candy Value Changed"
end

CandyChanged() 

CandyStore:OnUpdate(CandyChanged)


wait(1)


player:WaitForChild("leaderstats").Candy:GetPropertyChangedSignal("Value"):Connect(function()
	print(player.Name .. "Received Candy")
	print("Total Candies:" .. player.leaderstats.Candy.Value)

	if player.leaderstats.Candy.Value >= 90 and player.leaderstats.Candy.Value < 10001 then --- If the Amount of Candies is Highter than 750.... Then
		badges:AwardBadge(player.UserId, FirstId)
		print"Received badge X 3"

	else if player.leaderstats.Candy.Value >= 2500 and player.leaderstats.Candy.Value < 10001 then -- Award the Second badge
			badges:AwardBadge(player.UserId, SecondId)
			print"Received badge Y 5"

		else if player.leaderstats.Candy.Value >= 5000 then -- Award the Third badge
				badges:AwardBadge(player.UserId, ThirdId)
				print"Received badge 10 Z"

			end
		end  
	end
end) ----------------  Close the Function 

end)

for i, house in pairs(game.Workspace.HousesFolder:GetChildren()) do

if house:IsA("Model") and house:FindFirstChild("Doorbell") then

	local doorOpen = false

	local HouseButton = house.Doorbell.ClickDetector


	HouseButton.MouseClick:Connect(function(p)

		local CandyStorePlus = DataStore2("Candies", p)

		if doorOpen == true then
			print"You already Opened This Door..."
			return

		end

		if doorOpen == false then

			doorOpen = true

			wait(1)

			local cf = house.Door.CFrame
			house.Door.CFrame = cf * CFrame.Angles(0, math.rad(90), 0) + (cf.LookVector * house.Door.Size.X/2) + (cf.RightVector * house.Door.Size.X/2)

			wait(1)
			print"Hello Dude, take this candy"

			CandyStorePlus:Increment(4)

			wait(4)


			house.Door.CFrame = cf


			wait(10)
			doorOpen = false
			print"The Cooldown Ended, you can open this door again"

		end
	end)
end

end

1 Like

When you do print, why aren’t you using brackets?

1 Like

Can you expand On This So i understand ? :smiley:

1 Like

You need to use brackets for the print function, so instead of print"Hello world!" it would be print("Hello world!")

1 Like

Are you receiving any errors in the console in game?

1 Like

this has been fixed now but it only works in studio ?

1 Like

Is the place under the same universe as the badges?

1 Like

So you want a badge to be awarded at 80 candy?

1 Like

Yes it is and is working on studio

1 Like

thats a test amount but it would be like that

1 Like

Perfect, I will create a script for you.

1 Like

the systems working.
its just the badges are only granted in studio now not on the game.

1 Like
--/ Services\--
local BadgeService = game:GetService("BadgeService")

--/ Variables \--
local Players = game.Players:GetPlayers()
local AmountOfCandy = 80 -- Replace with the amount of candy the player has to have to get the badge!
local Badge = {
    [BadgeID] =  000000 -- Replace 000000 with your badge ID!
}

for i = 1, #Players do
    local CurrentPlayer = Players[i]

    if CurrentPlayer.leaderstats.Candy.Value >= AmountOfCandy and not BadgeService:UserOwnsBadgeAsync(CurrentPlayer.UserId, Badge[BadgeID]) then
        BadgeService:AwardBadge(CurrentPlayer, Badge[BadgeID])
    end
end

This should work, I made it off the top of my head so let me know if not! This will be a NORMAL Script. DO NOT add any more badge variables under the badge table. If you’d like another badge to be awarded for a different amount of candy, duplicate this script and change the CandyValue variable and the BadgeID.

2 Likes

where would this go
i alread yhave a trick or treat script and evertything

1 Like

This would be a normal Script, under ServerScriptService.

1 Like

ok heres the actual question: Did you receive debug logs in your game when you got the 80 (or 90) candy canes requirement

(did the console print anything and/or print Received badge X 3)

and you said you will get a badge on 80 candy canes but in your code its 90 candy canes

here’s a theory, you can’t get badges twice so when you got the badge on the studio you can’t get it from the game

maybe sending the link to your game (if you can) so we can try to help

2 Likes

shall i try output in studio ?

1 Like

no, you play the game in roblox player not studio and when you get 80 or 90 candy canes and check the output will it prints anything

1 Like

i deleted the badge. by the way

1 Like

developer console ? is that what i check

2 Likes