First of all im very bad at scripting.
So my issue is that I have a script which can give a badge when an npc is killed but for some reason it only works with a sword but not a rocket laucher. Any ideas how I could do it?
local badge = 0000000 -- the badge id
local npc = script.Parent
while npc ~= nil do
if npc.Humanoid.Health <= 0 then
local player = npc.Humanoid:FindFirstChild("creator")
if npc ~= nil then
if player and player:IsA("ObjectValue") and player.Value then
local userId = player.Value.UserId
game:GetService("BadgeService"):AwardBadge(userId, badge)
end
end
end
wait(1)
end
-- When a new character is made... Attach this code to its creation script.
-- Note, in the rocket script, detect when the rocket explodes,
-- and instead of having the explosion instance kill the target player, just kill them
-- if they're in a certain radius of the explosion position. With that manual kill, then you can assign
-- a player_killer attribute and death_reason that way.
new_character.Humanoid.Died:Once(function()
local death_reason = new_character.Humanoid:GetAttribute("death_reason")
local player_killer = new_character.Humanoid:GetAttribute("player_killer")
if not npc then
return
end
-- No need to check if "player" is an object value if your game is designed well.
if death_reason == "rocket" then
local userId = game:GetService("Players")[player_killer].UserId
game:GetService("BadgeService"):AwardBadge(userId, badge)
end
end)