How to find what player (or in game monster) killed you?
I want to get something like this (but working)
if you died then connect to function(killer) and gui.abc.text = "You died to "…killer.name
How to find what player (or in game monster) killed you?
I want to get something like this (but working)
if you died then connect to function(killer) and gui.abc.text = "You died to "…killer.name
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
Adding this function and calling in within your weapon, would make a tag under the target’s humanoid. Which then would help you get your ‘killer’.
thank you but can i get a monster that killed me (npc)
Once a player joins, Insert an object value named “DamagedHumanoid” or whatever you wanna call it in the player. like this:
game.Players.PlayerAdded:Connect(function(player)
local damagedHum = Instance.new("ObjectValue")
damagedHum.Name = "DamagedHum"
damagedHum.Parent = player
end)
If the monster kills someone add this lines of code to the script that kills players in the monster or enemy:
local enemyHum = enemy.Humanoid
local enemyPlayer = game.Players:GetPlayerFromCharacter(enemyHum.Parent)
if enemyPlayer then
if enemyPlayer:WaitForChild("DamagedHum") then
enemyPlayer:WaitForChild("DamagedHum").Value = script.Parent:WaitForChild("Owner").Value
end
end
Now to detect when the player dies, add this script into the starter character scripts.
local char = script.Parent
local player = game.Players:GetPlayerFromCharacter(char)
local damagedHum = player:WaitForChild("DamagedHum")
local hum = char:WaitForChild("Humanoid")
hum.Died:Connect(function()
if damagedHum.Value ~= nil then
print(damagedHum.Value.Name.." killed "..player.Name)
else
print("Unknown force killed "..player.Name)
end
end)
thank you but i cant set second solution