Hi, I was wondering how I would convert my badge script for killing the creator to work when you are killed BY the creator instead. Would I just switch some things around, or would it be different?
local badgeId = 575373257 function awardBadgeOnDeath(player, badgeId) player.CharacterAdded:connect(function(char) char.Humanoid.Died:connect(function() local killer = char.Humanoid:FindFirstChild("creator") if killer then game:GetService("BadgeService"):AwardBadge(killer.Value.userId, badgeId) end end) end) end game.Players.PlayerAdded:connect(function(player) if player.userId == game.CreatorId then awardBadgeOnDeath(player, badgeId) end end)
Also, this original script only works half the time. What's wrong?
First of all, let's remake the script to work for all players and be a little improved. I've split it up to 3 parts.
Minor fixes and removing the creator check.
What you need to do is remove the function awardBadgeOnDeath
and copy the script part and replace the if the player is a creator.
Checking who is the killer
But now it will award badges if you kill anyone?
We need to add an if question to see if the killer's id matches game.CreatorId
The Code
This is the code I managed to come up with.
local badgeId = 575373257 function awardBadgeOnDeath(player, badgeId) player.CharacterAdded:connect(function(char) char.Humanoid.Died:connect(function() local killer = char.Humanoid:FindFirstChild("creator") if killer then game:GetService("BadgeService"):AwardBadge(killer.Value.userId, badgeId) end end) end) end game.Players.PlayerAdded:connect(function(player) function awardBadgeOnDeath(player, badgeId) player.CharacterAdded:connect(function(char) char.Humanoid.Died:connect(function() local killer = char.Humanoid:FindFirstChild("creator") if killer then if killer.Value.userId = game.CreatorId then game:GetService("BadgeService"):AwardBadge(killer.Value.userId, badgeId) end end end) end) end end)
Firstly, we want to make sure you put the script into ServerScriptService. If this still doesn't work, try to move it in different places. Secondly, make sure you placed YOUR creator ID and YOUR badge ID.
The code bartekrabit came up with was this:
local badgeId = 0000 (PUT YOUR BADGE ID) local userId = 0000 (PUT YOUR USER ID) 02 03 function awardBadgeOnDeath(player, badgeId) 04 player.CharacterAdded:connect(function(char) 05 char.Humanoid.Died:connect(function() 06 local killer = char.Humanoid:FindFirstChild("creator") 07 if killer then 08 game:GetService("BadgeService"):AwardBadge(killer.Value.userId, badgeId) 09 end 10 end) 11 end) 12 end 13 14 game.Players.PlayerAdded:connect(function(player) 15 function awardBadgeOnDeath(player, badgeId) 16 player.CharacterAdded:connect(function(char) 17 char.Humanoid.Died:connect(function() 18 local killer = char.Humanoid:FindFirstChild("creator") 19 if killer then 20 if killer.Value.userId = game.CreatorId then 21 game:GetService("BadgeService"):AwardBadge(killer.Value.userId, badgeId) 22 end 23 end 24 end) 25 end) 26 end 27 28 end)
I've re-written it a bit and modified some stuff. You must put it in ServerScriptService and if it still doesn't work, seek further help from YouTube, google etc. Another suggestion would be placing the script in other places like WorkSpace, etc.
This script actually DID work for me so I'm guessing it'll help you aswell.
The reason it may not ALWAYS work was because you must've written something wrong in the script which i already covered. This IS for when you kill the owner and not when the owner kills you. Modifiying the script to make it when the owner kills you should be easy. There are some tutorials, if not many tutorials on YouTube for similar things. There are model scripts aswell so inserting them into your game wouldn't be a harm. If you want to learn how the script works if you didn't script it yourself, look through the script and make sense/search up what they mean.
Hope this all helped.
p.s: this worked for me.