How to give out badge, when person wins a round without losing any HP?

local bgs = game:GetService("BadgeService")
local id = 2128017553
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:WaitForChild("leaderstats")
	local cust = leaderstats:WaitForChild("Custards")
	local char = player.Character or player.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	onChange = cust.Changed:Connect(function()
		if cust.Value >= 10 then
			if hum.Health == 100 then
				if not bgs:UserHasBadgeAsync(player.UserId, id) then
					bgs:AwardBadge(player.UserId, id)
			       end
			end	
		end
	end)
end)

it still gives out badge even if i have less than 100 hp

1 Like

When they have 10 or more custards, do they win the round?

1 Like

yes,it works like slender. And i want it to give out badge when person collectes all of those custards without losing any hp

Can the players heal? For example, if I get damaged during the round, and heal up to 100 health, do you still want to give them the badge? (only if they can heal in your game)

1 Like

nope, they cant heal, i disabled healing through script

1 Like

Okay, change your script to this:

--//Services
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

--//Controls
local badgeId = 2128017553

--//Functions
local function AwardBadge(player, badgeId)
	local success, errorMessage = pcall(function()
		BadgeService:AwardBadge(player.UserId, badgeId)
	end)
	
	if not success then
		warn(errorMessage)
	end
end

Players.PlayerAdded:Connect(function(player)
	local custards = player:WaitForChild("leaderstats"):WaitForChild("Custards")
	
	custards.Changed:Connect(function(newValue)
		if newValue < 10 then
			return
		end
		
		local humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")
		
		if not humanoid or humanoid.Health < 100 then
			return
		end
		
		if not BadgeService:UserHasBadgeAsync(player.UserId, badgeId) then
			AwardBadge(player, badgeId)
		end
	end)
end)

it still gives me out a badge, idk why

Tell me what this prints:

--//Services
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

--//Controls
local badgeId = 2128017553

--//Functions
local function AwardBadge(player, badgeId)
	local success, errorMessage = pcall(function()
		BadgeService:AwardBadge(player.UserId, badgeId)
	end)

	if not success then
		warn(errorMessage)
	end
end

Players.PlayerAdded:Connect(function(player)
	local custards = player:WaitForChild("leaderstats"):WaitForChild("Custards")

	custards.Changed:Connect(function(newValue)
		if newValue < 10 then
			return
		end

		local humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")

		if not humanoid or humanoid.Health < humanoid.MaxHealth then
			return
		end
		
		print("Health:", humanoid.Health)
		print("MaxHealth:", humanoid.MaxHealth)

		if not BadgeService:UserHasBadgeAsync(player.UserId, badgeId) then
			AwardBadge(player, badgeId)
		end
	end)
end)

in the output, it says that my health is 100, but it is NOT 100, like i had 80
image

How do you damage the player? If they are damaged on the client, maybe the server can’t see the damage changes?

a better solution for this would be, a individual value called: “NoHit” boolvalue

then create a function detecting the health of the user

if somehow the health changes to something negative or below 100,
Nohit = true, then, after finishing the round, check if NoHit is FALSE, if FALSE, then give the badge, that means the user never lost Health

can be a intvalue from ''instance.new" or can be saved internaly if you got some datastore, but when the player joins the game again, make sure to Turn [NoHit] to false again, by default

im damaging the player using a localscript in startercharacterscripts, could this be a problem?

Yep, this is the problem. You need to damage them on the server.