Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to add a value on the players?

I want to award a badge to the player who killed the Boss. Im using this script under Boss Humanoid. How can I add a value on the players?

BadgeID =  2124659474

script.Parent.Died:connect(function()
	if script.Parent:FindFirstChild("creator") then --[ you should add a value on the players]
		game:GetService("BadgeService"):AwardBadge(script.Parent.creator.Value.userId,BadgeID)
	end
end)

1 answer

You can use local scripts in each player that interact with the boss's script to find out who damages or kills them by detecting if the boss health was 0 when you hit it. To do this, just use whatever attack method your using and you can do anything like setting a value, or if its a sword or something that touches it that the player is holding or belongs to the player in any way, then you can detect that with

LastPlayerToDamage = "none"




script.Parent.Touched:Connect(function(hit)

	for _,i in pairs(hit:GetAncestors()) do--gets every parent of every parent of the hit to detect if its related to a player

		for _,ii in pairs(game.Players:GetChildren()) do

			if i.Name == ii.Name then --if the related parent of the hit part is the name of a player then...
				LastPlayerToDamage = ii.Name --sets the player's name to a variable which you can use to give that player the badge
				

			end

		end

	end

end)










--your script here -vvv-
BadgeID =  2124659474

script.Parent.Died:connect(function()
    if not LastPlayerToDamage == "none" then --it continues if its not "none" meaning a player is in the variable, meaning they are the last player to damage the boss
        game:GetService("BadgeService"):AwardBadge(game.Players[LastPlayerToDamage].userID, BadgeID)
   

else --this is a fail safe, there is no reason the boss would be dead and nobody would be in the variable for damaging it, but just in case because that sometimes happens, this will be a fail safe so if it is stil none, then just dont  award the badge, because whatever you do, make sure your scripts dont break and cause unnecessary errors that could mess with other experiments.
 end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.