Anti-TeamKiller script does not damage NPCs?
Asked by
6 years ago Edited 6 years ago
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:
01 | handle.Touched:connect( function (hit) |
02 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
04 | local TargetPlayer = game.Players:GetPlayerFromCharacter(humanoid.Parent) |
05 | if equipped and character and humanoid and humanoid.Health > 0 and hit and not hit:isDescendantOf(character) then |
06 | if humanoid and humanoid.Health > 0 and not hithumanoids [ humanoid ] and (TargetPlayer.TeamColor ~ = player.TeamColor or not TargetPlayer) |
08 | hithumanoids [ humanoid ] = true |
10 | for _, v in pairs ( humanoid:GetChildren()) do |
11 | if v and v.Name = = "creator" then |
15 | local tag = Instance.new( "ObjectValue" ) |
18 | debris:AddItem(tag, 3 ) |
20 | humanoid:TakeDamage(damage * (combo + 1 )) |