I have this script for a hand axe that I'm making for a game, so far it works perfectly fine. Each time it hits a humanoid it deals damage. However I also want it so that it wont deal any damage to any of the player's team mates, and I have tried using GetPlayerFromCharacter however I am having trouble on figuring out how to use it in my code when the script detects that a humanoid has hit the handle.
Here is the snippet of my code that fixates on hit detection.
local canDamage = true
canChop = true
Tool.Handle.Touched:connect(function(hit)
if not swinging then return end
if not canDamage or not canChop then return end
function damage()
canDamage = false
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(26)
Tool.Handle.FleshHit:Play()
wait(coolDown2)
canDamage = true
end
local function chop()
canChop = false
local chopValue = hit.Parent.ChopValue
local addValue = 1
chopValue.Value = chopValue.Value - addValue
Tool.Handle.Chop:Play()
wait(coolDown2)
canChop = true
end
if hit and hit.Parent:FindFirstChild("Humanoid") then
damage()
elseif hit and hit.Parent:FindFirstChild("ChopValue") then --if hit tree then
chop()
end
end)

2 comments
No need to do "var == false", or "var == true", you can use "var" and "not var".
thanks made some few minor edits to the code that i posted