Hey there. So, in this game I'm currently developing, I have these enemy NPCs that you must attack. Right now, I've just added swords to the enemies, but they seem to cause damage to each other when the sword goes near them. This is the one part of the code from the LinkedSwords I've edited from them.
--Beginning sword code here function blow(hit) if (hit.Parent == nil) and (hit.Parent == "Blooborn") then return end -- happens when bullet hits sword local humanoid = hit.Parent:findFirstChild("Humanoid") local vCharacter = Tool.Parent local vPlayer = game.Players:playerFromCharacter(vCharacter) local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character if humanoid~=nil and humanoid ~= hum and hum ~= nil then -- final check, make sure sword is in-hand local right_arm = vCharacter:FindFirstChild("Right Arm") if (right_arm ~= nil) then local joint = right_arm:FindFirstChild("RightGrip") if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then tagHumanoid(humanoid, vPlayer) humanoid:TakeDamage(damage) wait(1) untagHumanoid(humanoid) end end end end --The rest of the sword code here
I'm not sure if I edited it correctly, so, my question is: How would I fix this part of the code? Cause I don't think Flow Control would have a key part in this..
That's not the best way to do it, because then 'NPC' will be above every enemies' head, which is probably not what he wants.
To do what I think you want, you need to check if it is a player.
This can be easily done by using game.Players:GetPlayerFromCharacter(character)
Therefore, you can just simply do this:
if not game.Players:GetPlayerFromCharacter(humanoid.Parent) then return end --Stops the function if the player does not exist.
Change the NPC's name to NPC(Model Name to NPC)
--Beginning sword code here function blow(hit) if (hit.Parent == nil) and (hit.Parent == "Blooborn") then return end -- happens when bullet hits sword local humanoid = hit.Parent:findFirstChild("Humanoid") local vCharacter = Tool.Parent local vPlayer = game.Players:playerFromCharacter(vCharacter) local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character if humanoid~=nil and humanoid ~= hum and hum ~= nil then -- final check, make sure sword is in-hand local right_arm = vCharacter:FindFirstChild("Right Arm") if (right_arm ~= nil) then local joint = right_arm:FindFirstChild("RightGrip") if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then tagHumanoid(humanoid, vPlayer) if humanoid.Parent.Name == "NPC" then print("Safe") else humanoid:TakeDamage(damage) wait(1) untagHumanoid(humanoid) end end end end end --The rest of the sword code here
If this helped +1, and make sure the website knows I answered k.