I was trying to find a killed the owner badge script for my sword fight game and all I saw is for NPC could someone help me to make this script?
just like how you would make a regular kill count script, you could check if the person you killed is you
You could just implement a PlayerAdded
, CharacterAdded
, and Humanoid.Died
Event to detect how this badge can work
First though we can go ahead, insert a script inside ServerScriptService
and get our Services that we’ll use & our BadgeID that we want to give all the Players to:
local BadgeID = 00000 --Placeholder, replace with your Badge ID
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
Next, we’d wanna implement our events by creating our PlayerAdded
Event first which will fire every time a player joins the server, and we can continue on from there:
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
end)
end)
end)
Then inside our Humanoid.Died
Event, we can then check if the Character
's Name is equal to the Owner’s Name & if it is, we can get a loop of all players to award the badge to:
if Character.Name == "uhLuvas" then
for _, Plr in pairs(Players:GetPlayers()) do
BadgeService:AwardBadge(Player.UserId, BadgeID)
end
end
This will ensure that the Owner
who died will award the badge to every player in the server!
In result, our full code should look something like this:
local BadgeID = 00000 --Placeholder, replace with your Badge ID
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
if Character.Name == "uhLuvas" then
for _, Plr in pairs(Players:GetPlayers()) do
BadgeService:AwardBadge(Plr.UserId, BadgeID)
end
end
end)
end)
end)
I don’t see how this will work as your just checking if the owner died. Your not checking who killed the owner
Uh, It tries to give it to me and not the person that killed me.
I forgot to reference a couple of things whoops
If you’re wanting to only have 1 player kill the Owner, just implement a creator
check:
local BadgeID = 00000 --Placeholder, replace with your Badge ID
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
if Character.Name == "uhLuvas" then
local creator = Humanoid:FindFirstChild("creator")
if creator and creator.Value then
local Killer = creator.Value
BadgeService:AwardBadge(Killer.UserId, BadgeID)
end
end
end)
end)
end)
Try not to mark my post as a solution unless if you actually know it worked cause 90% of the times I misread the topic