AI killing badge help

I am looking to make it so when an AI is killed it rewards everybody with a badge, however currently it only rewards it to whoever got the last hit. My current code is:

local badge = 4045197205634705
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

How can I edit this code to make it so everybody gets the badge?

2 Likes

could you format your code with the actual code feature, so i can read it

there is a format option simular to bold or italics when you type

Is it the blockquote? i’ve made the edit, haven’t used the devforum in years

Well reading from your code, I think you only referenced one player to get the badge.

try looping through all the players:

for i,player in game:GetService("Players"):GetPlayers() do
     game:GetService(“BadgeService”):AwardBadge(player.UserId, badge)
end
1 Like

Just use a for loop with in pairs(game:GetService(“Players”):GetPlayers())

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.