I have a sword script, however, there’s a section where if the player has the same TeamColor
as the player they are trying to kill, no damage is taken.
However, despite both players being on the same team, the target still takes damage if they are on the same TeamColor
as the hitter. Any insight on this would be appreciated.
local tool = script.Parent
local damage = script.Parent.Damage.Value
local Debris = game:GetService("Debris")
local function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
local function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
local function onTouch(partOther)
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
local player = tool.Parent
if not humanOther then return end
TagHumanoid(humanOther, player)
local playerTeam = player:FindFirstChild("TeamColor")
local otherPlayerTeam = partOther.Parent:FindFirstChild("TeamColor")
if playerTeam and otherPlayerTeam == otherPlayerTeam then
print("same team")
else
humanOther:TakeDamage(damage)
end
end
local function slash()
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)