Problems with issuing badges

Some time, I can’t figure out what I’m doing wrong. I need your help.

nhgn

I think your problem here is that when your game runs, this server script will run, find no players and do nothing and finish before the first player joins.

1 Like

I agree with them, you should try and delete the function but leave what’s in it. Because the event is nested in a function, it would only run once.

You should have your .Changed connection outside the function and within the if statement of your connection just call the awardbadge function

I totally missed that .changed connection. So I take back my first post, haha. So now I don’t know why its not working. Add some print statements to see what it is doing, then you’ll figure out what its not doing.

If you are doing this from a LocalScript, don’t, you need to award badges on the server side. And it’s better to use GetPropertyChangedSignal than .Changed.

Also use UserHasBadgeAsync to check if they already have the badge.

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

local BadgeId = 2125805786
local Wave = workspace:WaitForChild("GameTemp").Wave

Wave:GetPropertyChangedSignal("Value"):Connect(function()
	if Wave.Value == 1 then
		for _, player in pairs(Players:GetPlayers()) do
			task.spawn(function()
				if not BadgeService:UserHasBadgeAsync(player.UserId, BadgeId) then
					BadgeService:AwardBadge(player.UserId, BadgeId)
					print("Gave Badge Id: "..BadgeId..", to "..player.Name)
				else
					print(player.Name.." already had Badge Id: "..BadgeId)
				end
			end)
		end
	end
end)
1 Like