I know that there is a humanoid.Dies event and it can connect me to the player who killed it. But I want to find the player who kills the mob when the humanoid.Healthchanged event. In the code, "if currentHealth == 0" I want to figure out who the player is that made its health to 0.
As for giving exp to the player, I got that sorted it out. What I really need is, how to find the player's name who killed this mob.
humanoid.HealthChanged:Connect(function(newHealth)
local healthDifference = newHealth - humCurrentHealth
humCurrentHealth = newHealth
currentHealth = math.clamp(currentHealth + healthDifference, 0, maxHealth)
bar.Size = UDim2.new(1/maxHealth*currentHealth, 0, 1, 0)
healthTxt.Text = currentHealth .. "/" .. maxHealth
if currentHealth == 0 then
mob.Parent = game.ServerStorage
currentHealth = maxHealth
bar.Size = UDim2.new(1/maxHealth*currentHealth, 0, 1, 0)
healthTxt.Text = currentHealth .. "/" .. maxHealth
humanoid.Health = humanoid.MaxHealth
humanoid:MoveTo(Vector3.new(0, 0, 0))
mob.HumanoidRootPart.CFrame = spawnCFrame
print("died")
wait(respawnTime)
mob.Parent = workspace
end
end)

1 comment
Thank you AnasBahauddin, you taught me more uses for creator.value than I know