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

how to get a leaderstat value when the player kills a humanoid?

since there are rules about not getting free scripts, thats not what im here for. just wondering if there is a function that find the player who killed a humanoid. do you know of a link or something to help with this. i looked, and i couldnt find anything. i knwo it has something to do with the on.death thing, but what?

1 answer

The answer to this question depends on how you are dealing damage to the humanoid in question. Let's say you have a sword and within the humanoid's character, A script that listens for a touch input from a part named Sword. If the sword was a tool, you could get the name of the player from the tool and award the points from there. (I'm assuming that's what you want based on your last question.)


local h = script.Parent.Parent.Humanoid -- Assuming this is inside of the monsters torso or wherever

function onTouched(hit)
if hit.Name == ("Sword") then

script.Parent.LastAttacker.Value = hit.Parent.Parent.Parent -- Assuming the Sword handle is inside of a tool inside of the players backpack inside of the player.

-- Be sure there is a string  value named LastAttacker inside of the Model you are trying to damage! 

print ("LastAttacker.Value")

H.Died:connect(function()

local character = game.Workspace:FindFirstChild(script.Parent.LastAttacker.Value)
local player = game.Players:GetPlayerFromCharacter(character)

--And then however you increase their leaderstat here!


end

**I threw this together on the spot and have yet to test it. However, I hope this helps! Let me know if it did!

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