Attempt to Concatenate String with Instance Printing

I am trying to print a simple phrase including the person who killed the player. I keep getting the error for some reason. I am guessing there is a very easy fix to this that I am not seeing.

It says the problem is on the “print(Player.Name…” was killed by"…Killer)" line.

It’s in ServerScriptService:

Players = game:GetService("Players")
Players.PlayerAdded:connect(function(Player)
	print("Player Added")
	Player.CharacterAdded:connect(function(Character)
		print("Character Added")
		local Humanoid = Character:WaitForChild("Humanoid") 
		Humanoid.Died:connect(function() 
			print("Humanoid Died")
			if Humanoid:FindFirstChild("creator") ~= nil then
				local Killer = Humanoid:FindFirstChild("creator").value
				print(Player.Name.." was killed by"..Killer)
			end

		end)
	end)
end)

Any help and or guidance would be appreciated, thank you.

1 Like
Players = game:GetService("Players")
Players.PlayerAdded:connect(function(Player)
	print("Player Added")
	Player.CharacterAdded:connect(function(Character)
		print("Character Added")
		local Humanoid = Character:WaitForChild("Humanoid") 
		Humanoid.Died:connect(function() 
			print("Humanoid Died")
			if Humanoid:FindFirstChild("creator") ~= nil then
				local Killer = Humanoid:FindFirstChild("creator").Value
				print(Player.Name.." was killed by"..Killer)
			end
		end)
	end)
end)

it was simply a capitalization error

2 Likes

Nope that hasn’t seemed to fix it.

any new error???

can you try printing out Player.Name and Killer separately

1 Like

The code that you have above is not looking for the name of the Killer, just the instance. Try doing:
local Killer = Humanoid:FindFirstChild(“creator”).Name

That should work.

Realising there is an issue with above statement: You should just find the Humanoid’s Parent’s Name.

1 Like

wouldn’t the name of the instance be “creator”

1 Like

It works if I print them separately but I need them printed together.

image

Yeah exactly, I need the value.

Yeah, I changed my statement above

1 Like
Players = game:GetService("Players")
Players.PlayerAdded:connect(function(Player)
	print("Player Added")
	Player.CharacterAdded:connect(function(Character)
		print("Character Added")
		local Humanoid = Character:WaitForChild("Humanoid") 
		Humanoid.Died:connect(function() 
			print("Humanoid Died")
			if Humanoid:FindFirstChild("creator") ~= nil then
				local Killer = Humanoid:FindFirstChild("creator").Value
				print(Player.Name.." was killed by"..tostring(Killer))
			end
		end)
	end)
end)

does this fix your problem?

You are looking for the name of the thing that killed you, right?

1 Like

The humanoid’s parent’s name is the name of the palyer who died, not the name of the player who killed them

Okay, i needed that. So @D0RYU , that is probably right

1 Like

Yeah, that’s fixed it. What is “tostring”?

it will turn the value inside into a string

if it can’t be turned into a string it will be nil

1 Like

tonumber() is also a thing which will turn the value into a number or you could turn any base value into decimal value which is useful in some cases

1 Like

Alright, thank you for the help. :+1: