Invalid argument #2 (string expected, got Instance)

  1. What do you want to achieve? Keep it simple and clear!
    I want to add 1 to a value in Players[Killer]. Killer is the value that the Linked Sword gives under Humanoid when it dies.

  2. What is the issue? Include screenshots / videos if possible!
    Attempting to do Players[Killer] results in the following error:

Invalid argument #2 (string expected, got Instance)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I can’t think of any solutions, considering Killer IS a string value, right? I tried to look on the Developer Hub but found no answers pertaining to my specific situation

My code that gives the kills:

Players = game:GetService("Players")

Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Character) 
	local Humanoid = Character:WaitForChild("Humanoid") 
	Humanoid.Died:connect(function() 
			if Humanoid:FindFirstChild("creator") ~= nil then 
			local killer = Humanoid.creator.Value 
			local player = Players[killer]
			print(player.Kills.Value)
			player.Kills.Value =  player.Kills.Value + 1
			end 			       
		end)
	end)
end)

Well the easy solution is to make the player table use player instances instead of their names.

There’s also a cool Value instance called ObjectValue. ObjectValue can store a player, and as far as I can tell that would solve your problem.

  1. Change “creator” to an ObjectValue
  2. When setting creator.Value, set it to the Player instead of the player’s name (E.x. creator.Value = game.Players.iMajesticMuffins)

Correct me if I’m wrong on this but I think you can’t assign properties of an instance to a variable. So his problem would of been

Try using killer.Name because killer isnt a player instance or a string.

2 Likes