Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to Display the Killer's Name?

Hello!

I've got my death script, it works, I wanted to include a Gui/Frame/TextLabel that tweens by the screen when a player is killed, naming their killer.

This is the Script I have to do all the Death things, and the portion I've included addresses what I'm trying to do here:

--//Get Services
local replicatedstorage = game:GetService('ReplicatedStorage')
local serversettings = replicatedstorage.ServerSettings

--//EventFolder
local Events = ReplicatedStorage:WaitForChild("Events")
--//Events
local respawnDelay = 2
local killedbyvalue = replicatedstorage:WaitForChild('KilledByValue') -- Bool Value
local killedbytext = replicatedstorage:WaitForChild('KilledByText') --String Value
local deathmsg = script.KilledBy.Frame.DeathMsgText -- Text Label inside a Frame inside the Gui inside this Script.


game.Players.PlayerAdded:connect(function(player)
	
	player.CharacterAdded:connect(function(char)
		local hum = char:WaitForChild('Humanoid')
		hum.Died:connect(function()											
			local tag = hum:FindFirstChild('creator')
--Attempt to add the killer's name to a Gui/Frame/TextLabel			
local killername = tag.Value.Name
			
killedbyvalue.Value = true  --Makes the "Death Message"/Text Label visible to the player.
killedbytext.Value = "Killed by - " .. killername .. "" --Where I attempt to add the killer's name to the Text Label

--Tweening message
	deathmsg:TweenPosition(UDim2.new(0.5,-100,0.5,-25), "Out","Quint",0.3)
	wait(1.5)
	deathmsg:TweenPosition(UDim2.new(-1,0,0.5,-25), "In","Quint",0.4)
	wait(0.5)
	deathmsg.Position = UDim2.new(1.5,0,0.5,-25)
		
wait(respawnDelay)
player:LoadCharacter()

--More Death things

The error I receive is this: - ServerScriptStorage.DeathScript:21: attempt to index local 'tag' (a nil value)

Inside the Script is a Gui with a Frame, TextLabel, and a Local Script inside the Text Label:

local replicatedstorage = game:GetService('ReplicatedStorage')
local killedbyvalue = replicatedstorage:WaitForChild('KilledByValue') -- Bool Value
local killedbytext = replicatedstorage:WaitForChild('KilledByText')  --String Value

script.Parent.Visible = true
killedbyvalue.Changed:connect(function()
script.Parent.Visible = false
end)

Am I just mislabeling how to get the killer's name as the Error above would imply? If so, please advise on how to correct my script. :) Thank you!

1 answer

✓ Accepted answer

The error is appearing because "creator" doesn't exist.

local tag = hum:FindFirstChild('creator')

if tag and tag:IsA("ObjectValue") and tag.Value and tag.Value:IsA("Player") then
	local killername = tag.Value.Name
	-- put the rest of the code here
end

This discussion is preserved as it was. New answers, comments, and votes are closed.