How I make a badge when an NPC kills you?

You can write your topic however you want, but you need to answer these questions:
So, I know how to use function(hit) but to reward a badge isn’t something I know well.

Currently in this game when a zombie kills you it rewards a badge. I’ve tried this:

game:GetService(“BadgeService”) — Gets the badge

game.Workspace.Zombie1.Kill (function(die)

game.Players.LocalPlayer.Death.name = “Death”

when player.died do

Player.Death = true
when Player.Death = true then

game:GetService(“BadgeService”)

local badge id = 1 —The badge’s ID

       end
end)

I have tried doing this but it didn’t do anything. This script is the thing I entered into playerservice.

1 Like

Hm

Well, here’s the thing: You’d need to add some sort of conditional check in order to detect which specific NPC exactly killed you, say if a Character just resetted themselves then they could just obtain the badge easily

What you could potentially do, is that when the Zombie attacks you, you can insert a CreatorTag which basically tags the Player, so that you can confirm when the Player dies from the Zombie itself

--After damaging the Player
local Creator = Instance.new("ObjectValue")
Creator.Name = "creator"
Creator.Value = ZombieName
Creator.Parent = Target

game.Debris:AddItem(Creator, 3)

Of course, you’d then have to check what badge you want to award them as well

Do keep in mind that AwardBadge() can only be called on the server, so you’ll have to use a ServerScriptService to accomplish this

We can use what’s called PlayerAdded & CharacterAdded Events, which will both fire whenever a Player/Character is added into the game

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local BadgeIDHere = 0 --Placeholder, replace this with what ID you want

local function PlayerAdded(Player)
    Player.CharacterAdded:Connect(function(Character)
        local Humanoid = Character:WaitForChild("Humanoid")
    end)
end)

Players.PlayerAdded:Connect(PlayerAdded)

Next, we want to create a Event that’ll focus mainly detecting if the Humanoid has died or not, which would be the Died Event:

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local BadgeIDHere = 0 --Placeholder, replace this with what ID you want

local function PlayerAdded(Player)
    Player.CharacterAdded:Connect(function(Character)
        local Humanoid = Character:WaitForChild("Humanoid")

        Humanoid.Died:Connect(function() --This will fire when the Character's Health is 0
            local CreatorCheck = Humanoid:FindFirstChild("creator") -- Checking if there's a valid object named "creator"

            if CreatorCheck and CreatorCheck.Value then
                local Killer = CreatorCheck.Value

                if Killer.Name == "Zombie1" then --Checking the name of the specific Killer
                    BadgeService:AwardBadge(BadgeIDHere)
                end
            end
        end)
    end)
end)

Players.PlayerAdded:Connect(PlayerAdded)

Of course this is just an example, but if you have any questions do feel free to ask

2 Likes