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

Is there a way to know who killed a player?

So i need this but dont know where to start I need to reward the player for killing another player. I dont know how to?

2 answers

✓ Accepted answer

You will need to add this to your tool script : (where the player gets damage)

local tag = Instance.new("StringValue")
tag.Value = KillerName --The name of the player who owns the tool
tag.Name = "creator"
tag.Parent = HitHumanoid --The Humanoid of the player who got damage
game:GetService("Debris"):AddItem(tag,.5)

You will need a script which detects if a player die :

--//Settings\\--
local amt = 1 --//Edit 1 to the number of Points you want to give to the player
local currencyName = "Points" --Change Points to your currency name

--//Script\\--
game.Players.PlayerAdded:connect(function(player)

    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
	

            local tag = character.Humanoid:FindFirstChild("creator")


            if tag ~= nil then
	
                if tag.Value ~= nil then



                    -- Here tag.Value is the player who killed us, so find their leaderstats
                    local statsKiller = tag.Value:FindFirstChild("leaderstats")
                    if statsKiller then
	
                        -- Award the Points to the player that killed us
                        statsKiller.Points.Value = statsKiller.Points.Value + amt
                    end

                end
            end
        end)
    end)
end)

1 comment

0

Thanks!

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