onPlayerKilled killerID always -1

So I’m trying to give a weapon to a player who kills another player using onPlayerKilled. The problem is that the killerID is always -1

This is the server script:

RegisterNetEvent("baseevents:onPlayerKilled")
AddEventHandler("baseevents:onPlayerKilled", function(killerID, deathData)
	local victim = source
    print("victim: "..tostring(victim).." | killer: "..tostring(killerID))
    TriggerClientEvent("test", killerID, victim)
end)

The message in the console:

victim: 8 | killer: -1

No matter how the killer kills and who kills.

If someone knows how to help me please reply, thanks!

You have to specify the killer as an id. In this snippet you are not specifying killer as anything. Try

PlayerPedId() for “killer”

When you are testing it how do you die ?
Through a Vehicle ?

No, this is a Baseevent.
See in Docs it should return what he wants.
I think he just is not getting killed by smth. other than some vehicles because that explains the result.

1 Like

Nope, I was testing it with other players with weapons not vehicles