Character Reset Badge Script Help

Hey everyone,

I am trying to create a script that awards a player a badge for resetting their character. I made this script but it doesn't seem to work. What am I doing wrong here, and how do I fix it? Thank you!


game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function(player)
			game:GetService("BadgeService"):AwardBadge(character.userId, 123)
			end)
		end)
end)

Edit: the “123” is just a dummy for the actual badge ID. I haven’t created the badge yet. However, I am checking the console for the message that the badge is given.

Is that your actual code? (stupid question ik)

Probably CharacterAdded it’s being connected after the Character loads. Instead use a variable to check if the character already exists.

Character doesn’t have a property that returns UserId, but the player has. Also make sure you change the 123 number to the actual badge id.

game:GetService('Players').PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	
	character:WaitForChild("Humanoid").Died:Connect(function()
		game:GetService("BadgeService"):AwardBadge(player.UserId, 123)
	end)
end)

No, see the edit to the top message

I tried it, but it did not work. Does it belong to a specific folder, or is there still another error?

game:GetService('Players').PlayerAdded:Connect(function(Player)
        Player.CharacterRemoving:Connect(function(Character)
      end)
end)

this would probably be better way to define character

Why? There’s no difference between those two methods.

I think I’ve had problems before where Character loads too fast, so just to ensure this I prefer checking before if the character already exists.

my bad i read it wrong but this might work

game:GetService("Players").PlayerAdded:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait() or nil
	local Humanoid = Character:FindFirstChild("Humanoid")
	
	
	Humanoid.Died:Connect(function()
        game:GetService("BadgeService"):AwardBadge(Player.UserId, 0)
		print("Awarding Badge to "...Player.Name)
	end)
end)

the print should tell you if the badge was sent

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

local badgeId = 0 --Change to ID of badge.
local playerBadges = {}

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			if not playerBadges[player] then
				local success, result = pcall(function()
					return badges:AwardBadge(player.UserId, badgeId)
				end)
				
				if success then
					if result then
						print(result)
						playerBadges[player] = true
					end
				else
					warn(result)
				end
			end
		end)
	end)
	
	local success, result = pcall(function()
		return badges:UserHasBadgeAsync(player.UserId, badgeId)
	end)
	
	if success then
		if result then
			print(result)
			playerBadges[player] = true
		end
	else
		warn(result)
	end
end)

players.PlayerRemoving:Connect(function(player)
	if playerBadges[player] then
		playerBadges[player] = nil
	end
end)

Just wrote up this script which works (tested), you just need to change the badge ID to that of a badge which belongs to your game. It should go without saying but this needs to be a server script (only the server can distribute/award badges).