Problem with Badges

Hello everyone! I have badges in my game, and it works. BUT, I have a two problems.

  1. I have “Treasure Found” value in leaderstats, and for example when player collected 20 treasures, player should get a badge. But in my game, it happens for example only when player has more then 20 or even when player have already 34 treasures collected.

    And it happens with “Meet the Developer” badge too. Only “Welcome” badge is working perfectly.

  2. I have “Meet the Developer” badge in my game, and in the game, there is Developer Chest that you can obtain only when you have the badge, but, it’s not working. I tried everything but I don’t give any Chest.

Here is BadgesHandler script:

local players = game:GetService("Players")
local badgeService = game:GetService("BadgeService")

local developerIDs = {2060318936, 313480731, 1817965508};
local welcomeID, meetDevID = 2149645743, 2149645969
local firstTrID, tenthTrID, twentyTrID = 2149646114, 2149671648, 2149671682
local thirtyTrID, fortyTrID, fiftyTrID = 2153818820, 2153818848, 2153818874

local rs = game:GetService("ReplicatedStorage")
local event1 = rs.Remotes.Events.TreasureCollect
local event2 = rs.Remotes.Events.AlreadyTaken

local creatorInGame = false
players.PlayerAdded:Connect(function(plr)
	local userID = plr.UserId
	if not badgeService:UserHasBadgeAsync(userID,welcomeID) then
		badgeService:AwardBadge(userID,welcomeID)
	end
	local treasuresFound = plr.leaderstats["Treasure Found"]
	if table.find(developerIDs, userID) then
		makerInGame = true
		local plrs = game:GetService("Players"):GetPlayers()
		for i,v in pairs(plrs) do
			if not badgeService:UserHasBadgeAsync(v.UserId, meetDevID) then
				badgeService:AwardBadge(v.UserId, meetDevID)
				local boolValue = plr.Treasures:FindFirstChild("DeveloperChest")
				if not boolValue.Value then
					event1:FireClient(plr, "Developer Chest", Color3.fromRGB(128, 187, 219), "Insane")
					plr.leaderstats["Treasure Found"].Value += 1
					boolValue.Value = true
				else return event2:FireClient(plr) end
			end
		end
	elseif makerInGame then
		if not badgeService:UserHasBadgeAsync(plr.UserId, meetDevID) then
			badgeService:AwardBadge(plr.UserId, meetDevID)
			local boolValue = plr.Treasures:FindFirstChild("DeveloperChest")
			if not boolValue.Value then
				event1:FireClient(plr, "Developer Chest", Color3.fromRGB(128, 187, 219), "Insane")
				plr.leaderstats["Treasure Found"].Value += 1
				boolValue.Value = true
			else return event2:FireClient(plr) end
		end
	end
	while wait(5) do
		treasuresFound.Changed:Connect(function(newValue)
			if newValue > 0 and not badgeService:UserHasBadgeAsync(userID, firstTrID) then badgeService:AwardBadge(userID, firstTrID) end
			if newValue > 9 and not badgeService:UserHasBadgeAsync(userID, tenthTrID) then badgeService:AwardBadge(userID, tenthTrID) end
			if newValue > 19 and not badgeService:UserHasBadgeAsync(userID, twentyTrID) then badgeService:AwardBadge(userID, twentyTrID) end
			if newValue > 29 and not badgeService:UserHasBadgeAsync(userID, thirtyTrID) then badgeService:AwardBadge(userID, thirtyTrID) end
			if newValue > 39 and not badgeService:UserHasBadgeAsync(userID, fortyTrID) then badgeService:AwardBadge(userID, fortyTrID) end
			if newValue > 49 and not badgeService:UserHasBadgeAsync(userID, fiftyTrID) then badgeService:AwardBadge(userID, fiftyTrID) end
		end)
	end
end)
players.PlayerRemoving:Connect(function(plr)
	local userID = plr.UserId
	if table.find(developerIDs, userID) then
		makerInGame = false
	end
end)

I’m not asking to write a new code, I need only tips or hints how I can change it and improve so it will work perfeclty. If someone help, that would be really appreciated! Thanks.

2 Likes

I think the problem lies within the “makerInGame” variable. First of all, it seems like you don’t declare it anywhere.

3 Likes

Thank you so much! How I didn’t even see that variable…

2 Likes

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