So I want to create a death log, but theres 1 small problem, to do this, I want the player who killed the players name (name of the killer) and also the name of the victim, but I can only get the victims name, how could I get the other players name?
Try posting your current code. It would be useful if we could see it. Knowing how your system is setup can help us figure out a good way to solve the problem that does not have any or to much conflict with the way you have everything already set up.
In order to get the killer’s name and victim’s name you need the handle all the death log functionality inside the weapon code.
You’d want a remove event called for example “AddDeathToDeathLog”
Inside the weapon code, add functionality in code so that every time the weapon damages a player run an if statement to check if the player the weapon was attacking died. If the player died, from that if statement call on the remove event from earlier and supply it the argument of the local player holding the weapon and the person the weapon just damaged and killed.
Example: This code is not real, I am showing it just to show you how the code would be written.
Event - When weapon attacks a Player
if playerBeingAttacked.Character.Humanoid.Health <= 0 then
-- weapon damaged player...
-- fire remote event and supply arguments (game.Players.localplayer, playerBeingAttacked)
end
end
Then you will need server side code to handle the functionality when the remote event is fired. From the server side code, log the data.
Server Side Example This code is not real, I am showing it just to show you how the code would be written.
onRemoteEventFired(killer,victim)--
-- log killer.Name and victim.Name
end
One thing roblox uses in their tools to figure out how killed a player was these “creator” tags
Every time a player is hit by another player’s weapon, a “creator” tag, which is an ObjectValue, is created and parented to their humanoid, referencing the player who hit them and destroyed after a few seconds. If the player died, you can check the “creator” tag in the humanoid that just died and you can get the player who killed them.
You can apply this same system and making the “creator” tag will have to be done in the weapon’s scripts