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