How do i know who the player died of?

Hello So im making an game that you have to kill other people to gain their time. But i ran into a problem because i do not really know how to get the player died of. I have already tried looking on the devforum for solutions and on the internet.

3 Likes

I do not know much but maybe use a server script because every person needs to see it right?
and needs a GUI

Roblox itself won’t give you exactly who killed who (as far as I know)
In your script, you can detect when someone kills someone else though.
For example, if a player kills another with a sword, check after they hit someone if it might’ve killed the player.

When a player kills someone you could fire a remoteevent that stores the player and the player that was killed.

You will need to create a player state-tracking system to accomplish this. The easiest way would be to handle the information on the client and then send the information to the server via a remote event. However, NEVER DO THAT. That would be one of the easiest systems to exploit and player could just fire the remote event to rack up massive scores that they didn’t have to work for.

A server-sided solution is necessary to accomplish this. What you want to do have it so every time a player wants to fire a weapon or swing a sword or something they fire a remote event to the server. The server then handles the process of firing the bullet or damaging someone when the sword hits another player. When damaging the player, you then want to check if the amount of damage you are performing to them is greater than the current health their humanoid has. If so, then you can fire a function or whatever to send a message or give the killer a reward.

Server Script:

local function KilledPlayer(killer,victim)
    print(killer.Name .. " killed " .. victim.Name)
end

ExampleRemoteEvent.OnServerEvent:Connect(function(player,...) -- own custom variables to pass from the client to the server
    -- Code to fire bullet, swing sword, ect.

   if victim and damage >= victim.Character:FindFirstChildWhichIsA("Humanoid").Health then
       KilledPlayer(player.Name,victim.Name)
   end
end)
2 Likes

You would have to go into weapon code, find where the damage code is, and then when the health of the player you are damaging is 0 or less, put some code.

Some gun models (especially if you’re using free model guns) add an object value instead of the dead humanoid called “creator” refering to the player who killed then

local function getKiller(char)
  local KillerValue = char.Humanoid:FindFirstChild("creator")
  if KillerValue and KillerValue.Value then
    return KillerValue.Value -- returns the player value of the killer
  else
    return nil
  end
end

game.Players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function(char)
    char.Humanoid.Died:Connect(function()
      local killer = getKiller(char)
      -- do the code with the found killer 
    end
  end
end)

Otherwise I have no idea

I’m using the regular Sword by ROBLOX

Ok, so go in the scripts for the sword, find where it deals player damage, then after that code add an if statement that checks wether the players health is greater than 0. If it’s not, then add some kill code.

Btw if you aren’t aware on how CreatorTags (Or Kill Checks/Seeing Who Died) work, I suggest looking at this post & the 1 below it as well :slightly_smiling_face:

2 Likes