I have a problem with a script that when an npc die for some reason gives only one player, and not all.
The script:
local Players = game:GetService("Players")
local Humanoid = script.Parent:WaitForChild('Humanoid')
BadgeID = 2124785121
Humanoid:GetPropertyChangedSignal("Health"):Connect(function(value)
if Humanoid.Health <= 0 then
for i, v in pairs(game:GetService("Players"):GetPlayers()) do
BadgeService:AwardBadge(v.UserId, BadgeID)
end
end
end)
Those code looks like it’s finding all the players in the server and awarding the badge to them all.
Here, it says that when the humanoid’s health is 0 (or killed) this will fire, which is correct. Then this part; for i, v in pairs(game:GetService(“Players”):GetPlayers()) do
BadgeService:AwardBadge(v.UserId, BadgeID)
This is finding the players using GetPlayers() and then giving it to all of the Players if found. You’ll need to find the player who killed the NPC.
You could try searching on YouTube on how to give a player a badge/reward for killing a NPC. It will give you a visual example that you can modify to your needs.
Some other things I found:
You may also want to search up on the DevForum too for more help. I’ve seen quite a few questions similar to yours that may help you.
Hmm the only thing I can think of is that the part of the script that awards the badge is only running one time or for only one player. Maybe you could check using prints to see what player was given it and how many times it runs?
Instead of doing that, maybe you could do a loop that keeps running and checking for the humanoid’s health to be 0. Then you make a variable that is basically Getting the service Players and GetPlayers(). Once that’s done, you could just get the players UserID and give the badge.
For example:
while wait() do
if humanoid.Health <= 0 then
local players = game.GetService(“Players”):GetPlayers()
BadgeService:AwardBadge(players.UserID, BadgeID)
end
end
(Sorry if the format is wrong)
This is the only thing I can really think of.
No problem. Sorry I couldn’t find the solution to help you. I’m not that good with some things. Hopefully you will find the solution soon. If I think of something that may help, I will let you know here.