Trying to do quest system

How do I check what killed the humanoid?

1 Like

in the part that has the dmg script make a string with the name of it and when the player is touched AND dead it will run, kinda like this:

local dead = false
script.Parent.Humanoid.Died:Connect(function()
dead = true
end)

script.Parent.Torso.Touched:Connect(function(part)
	if dead and part.Name == (damage part name) then
		print(part.Name)
	end
end)

script.Parent.Head.Touched:Connect(function(part)
	if dead and part.Name == (damage part name) then
		print(part.Name)
	end
end)

script.Parent['Left Arm'].Touched:Connect(function(part)
	if dead and part.Name == (damage part name) then
		print(part.Name)
	end
end)

script.Parent['Left Leg'].Touched:Connect(function(part)
	if dead and part.Name == (damage part name) then
		print(part.Name)
	end
end)

script.Parent['Right Arm'].Touched:Connect(function(part)
	if dead and part.Name == (damage part name) then
		print(part.Name)
	end
end)
script.Parent['Right Leg'].Touched:Connect(function(part)
if dead and part.Name == (damage part name) then
	print(part.Name)
end
end)

EDIT: probably a better way to do this i just kinda threw it together

1 Like

it is a ball that is killing the npc how do i identify which is the ball that is killing the npc? (the ball already has a damage script, and has a stringvalue with the name of the player that owns the ball)

You can add a tag to the humanoid each time their damaged and set the value to the user who damaged the player, but you’ll need to modify your weapon scripts to do this if they don’t have it yet.

When Humanoid.Died is called check if the tag exists, if it does then use the value property to get who killed them.

(For npc’s I’d insert a StringValue inside the player’s humanoid and the value would be what npc they killed)

.Touched:Connect(function(part)

part defines the part that touched it, and if the parts name is like bullet or smthn then part is the thing it wants and prints its name

@C0d3k1d
@flkfv
I can’t do what I’m asking but I know touched event is the worst way to do it

It depends on how you are doing the damage.

If you are doing raycast then it’s pretty easy. Simply along with the raycast send the data to the player or thing that was hit.

If you are doing touched then you can use a ModuleScript to check who damage what and who was the last to hit.

It’s also the same if you are doing region3 or magnitude.

“then you can use a ModuleScript”

speaking from your perspective what I want is the module script code

Okay then. Here is a simple way you can do it.

-- ModuleScript
local DamageController = {}
function DamageController:AddCharacter(Player)--Every Player needs the reference, the health, and the last thing which it was damaged by
    self.PlayerList[Player] = {nil}-- I am only storing the player who damaged it last
end
function DamageController:DamageCharacter(Victim, Assailant, DamageAmount)
    local Character = Victim.Character
    local Humanoid = Character.Humanoid
    Humanoid:TakeDamage(DamageAmount)
    self.PlayerList[Victim][1] = Assailant
    if Humanoid.Health < 1 then
        return self.PlayerList[Victim][1]
    end
end

return DamageController

The use of that module you can add a lot more things to it for example you can add a function where if the player leaves or resets you still have the last known assailant stored in the Module

-- Script on the server
local DamageController = require(<wherever your module is located>)--yeah..

Players.PlayerAdded:Connect(function(Player)
    DamageController:AddCharacter(Player)-- Putting the character in the module
end)

RemoteEventThatHandlesDamage.OnServerEvent:Connect(function(Player,Victim,Damage)
    -- Of course you do the sanity checks here.
    DamageController:DamageCharacter(Victim, Player, Damage)
end)

When the part is touched you have to get the player and the victim like this

Part.Touched:Connect(function(Hit)
    local char = hit.Parent
    if Players:GetPlayerFromCharacter(char) then
         RemoteEventThatHandlesDamage.OnServerEvent--Yeah you get the idea
    end
end)

This is just a basic way of handling the damage. If you are using projectiles then you can even make a module that stores who fired the projectiles too and merge it with the damage module.

  1. What is this sanity check?
  2. How i can store my projectiles?