Hi everyone. I have a sword that does not do team damage to players on the same team. However that caused an issue for the sword not doing damage to monsters because they are not on a team.
I put a part inside the monster and welded it to the torso. The part is called Mob. Is there a way to have the script detect if the humanoid has that part then it will also do damage to the monster. Ill link the swords damage script below.
local weapon = script.Parent
local dmg = 50 -- Change the damage value here
local hitsound = script.Parent.Parent.Handle.hitsound
weapon.Touched:connect(function(part)
if part.Parent:findFirstChild("Humanoid") then
local humanoid = part.Parent:findFirstChild("Humanoid")
local character = humanoid.Parent
local hitPlayer = game.Players:GetPlayerFromCharacter(character)
local wieldingPlayer = game.Players:FindFirstChild(weapon.Parent.Parent.Name)
if hitPlayer.Team ~= wieldingPlayer.Team then
humanoid:TakeDamage(dmg)
hitsound:Play()
script:Destroy()
end
end
end)
I was thinking changing
if hitPlayer.Team ~= wieldingPlayer.Team then
to something like
if hitPlayer.Team ~= wieldingPlayer.Team or (humanoid has part Mob)
I have tried to enter it a few different ways but have been unsuccessful. So I wrote in what I think needs to happen.
Does anyone agree this would solve the issue? Or is there a better way to achieve this goal.
Thanks very much in advance. I always appreciate your help.
local weapon = script.Parent
local dmg = 50 -- Change the damage value here
local hitsound = script.Parent.Parent.Handle.hitsound
local players = game:GetService("Players")
weapon.Touched:connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
local hitPlr = players:GetPlayerFromCharacter(part.Parent)
local character = hitPlr.Character
local humanoid = character:FindFirstChild("Humanoid")
local hittingPlr = players:GetPlayerFromCharacter(weapon.Parent)
if not hitPlr.TeamColor then --hitting an npc that isnt in a team
--do code
return
end
if hitPlr.TeamColor ~= hittingPlr.TeamColor then
humanoid:TakeDamage(dmg)
hitsound:Play()
end
end
end)
since you’re working with ‘‘teams’’
mobs must have their own ‘‘team’’ too, otherwise they won’t be counted as something in your function
For example
i would do this:
local character = humanoid.Parent
local hitPlayer = game.Players:GetPlayerFromCharacter(character)
local wieldingPlayer = game.Players:FindFirstChild(weapon.Parent.Parent.Name)
local Mob = game.Workspace:FindFirstChild(Reference of a Model with humanoid here)
if hitPlayer.Team ~= wieldingPlayer.Team or Mob.Team then --
local weapon = script.Parent
local dmg = 50 -- Change the damage value here
local hitsound = script.Parent.Parent.Handle.hitsound
weapon.Touched:connect(function(part)
if part.Parent:findFirstChild("Humanoid") then
local humanoid = part.Parent:findFirstChild("Humanoid")
local character = humanoid.Parent
local hitPlayer = game.Players:GetPlayerFromCharacter(character)
local wieldingPlayer = game.Players:FindFirstChild(weapon.Parent.Parent.Name)
if hitPlayer then
if hitPlayer.Team ~= wieldingPlayer.Team then
humanoid:TakeDamage(dmg)
hitsound:Play()
script:Destroy()
else
if humanoid:FindFirstChild("Mob") then
humanoid:TakeDamage(dmg)
hitsound:Play()
script:Destroy()
end
end
end
end)