I'm trying to make a sword and the code below is in a regular script, inside the sword.
I want it to be that if you hit an enemy with the sword the enemy is damaged by whatever damage is in the script (obviously) but I don't want the sword to deal damage to you or your teammates.
damage = 5 Saber2 = script.Parent.Saber2 function DealDamage() end Saber2.Touched:connect(DealDamage)
I'm not sure what I should put in the DealDamage function, or if that's the best way to go around doing this.
Could someone tell me what I need to put in the function or if there is a better way to be doing this?
Thanks.
First thing you'd want is to check if the item touched is a player then check if they are in your team than damage if false here is the function you should use. Assuming the script is inside the character.
local damage=5 local player=game.Players:GetPlayerFromCharacter(script.Parent) function Touched(hit) local hum=(hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")) or nil if hum~=nil then local plyr=game.Players:GetPlayerFromCharacter(hum.Parent) if plyr~=nil then if plyr.TeamColor~=player.TeamColor then hum:TakeDamage(damage) end end end end
Please rep if you like this and yes I know it can be shortens but this guy won't get it if it is.