Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Make this function trigger only if the local player is the person who killed the humanoid?

Asked by 8 years ago

Is there a way to make this function only work if the local player is the killer?

local Array = require(game.Workspace.Inventory)
local inventory = Array[1]
local addItem = Array[2]

function onDeath ()

    addItem("Gun")
    print("boss killed")

end

game.Workspace.NPC:WaitForChild("Humanoid").Died:connect(onDeath)

Yes, this code works but adds the Gun to everyone. I have a modulescript set up to do this but I don't think it's necessary to post it here so I left it out, thanks!

1 answer

Log in to vote
0
Answered by 8 years ago

Yes, but you have to keep track of the player(s) who were attacking your NPC. Roblox's leaderboard script has a way of doing this that the old/classic weapons follow; you could adapt their system.

If it's possible for more than one player to help kill the boss and you want to reward all of them, you could just simplify it and give it to all those who are within a certain distance of the boss when the boss is killed. This is easier to script, but it's prone to rewarding people who are nearby but didn't participate and not rewarding someone who died at the last moment (yet did most of the work in killing the boss).

Ad

Answer this question