Not sure why value isn't being detected correctly

I’m currently making a unique assassins sword where when you equip it you are given a target to kill. When a target is found, a value named TargetValue is set to the targets name. When the sword is touched by a humanoid, the following if statement is written in the code. To see if there is a target or not I have used if TargetValue.Value == “” --do stuff elseif TargetValue.Value ~= “” --do stuff. Although when TargetValue.Value holds the name of a player, “player not detected” is printed (see the following code)

if TargetValue.Value ~= "" then
		print("player detected")
		Player_Target = true
		Other_Target = false
		if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Name == TargetValue.Value then
			EnemyHumanoid = Hit.Parent:WaitForChild("Humanoid")
		elseif Hit.Parent.Parent:FindFirstChild("Humanoid") and Hit.Parent.Parent.Name == TargetValue.Value then
			EnemyHumanoid = Hit.Parent.Parent:WaitForChild("Humanoid")
		else return end
elseif TargetValue.Value == "" then
	print("player not detected")
	Player_Target = false
	Other_Target = true
	if Hit.Parent:FindFirstChild("Humanoid") then
		EnemyHumanoid = Hit.Parent:WaitForChild("Humanoid")
	elseif Hit.Parent.Parent:FindFirstChild("Humanoid") then
		EnemyHumanoid = Hit.Parent.Parent:WaitForChild("Humanoid")
	else end
else end

if anyone could help that would be great. I can also provide the tool for fixing which would be appreciated

Are you getting any error? also you should format that first block of code

No errors. How do I format it?

Ok got it formatted. Yeah so no errors. It just always prints “player not detected” even when the value holds the players name. essentially does the second block of code all times

It might be if the value is set by a local script. It can not be read by normal script.

It was indeed set by a local script. I’ll let you know if it still doesn’t work, I’ll do some tweaking