Hello,
EDIT: Original anti-TK script was sorted out, reposting the now correct script with the new weird issue.
I have a sword script, thanks to user ScrewDeath, I was able to fix the error. But now, I can not inflict damage on NPCs who all have the "Humanoid" property. Do I need to set them to a team?
Error is: 00:42:31.079 - Players.Player1.Backpack.BasicSword.SwordScript:6: attempt to index local 'TargetPlayer' (a nil value)
Damage section of the Sword Script:
handle.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local TargetPlayer = game.Players:GetPlayerFromCharacter(humanoid.Parent)
if equipped and character and humanoid and humanoid.Health > 0 and hit and not hit:isDescendantOf(character) then
if humanoid and humanoid.Health > 0 and not hithumanoids[humanoid] and (TargetPlayer.TeamColor ~= player.TeamColor or not TargetPlayer)
then
hithumanoids[ humanoid] = true
for _, v in pairs( humanoid:GetChildren()) do
if v and v.Name == "creator" then
v:remove()
end
end
local tag = Instance.new("ObjectValue")
tag.Name = "creator"
tag.Value = player
debris:AddItem(tag, 3)
tag.Parent = humanoid
humanoid:TakeDamage(damage * (combo + 1))
else
end
end
end
end)

2 comments
Why do you create an ObjectValue for no reason?
For the damage portion. :) Do you have thoughts on the line I pointed out where the TeamColor is wrong?