Hi there, I am trying to make an Anti-TeamKill script. I am using the PaintballGun as a template for that. The problem is that instead of not dealing damage to teammates, it does not deal damage to everyone. The code is pasted below:
ball = script.Parent
damage = 20
teamD = 0
connection = ball.Touched:connect(onTouched)
function onTouched(hit)
if hit.Name == "Bullet" then return end
local humanoid = hit.Parent:FindFirstChild("Humanoid")
connection:disconnect()
if humanoid ~= nil then
tagHumanoid(humanoid)
local target = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent ~= nil then
if game.Players:GetPlayerFromCharacter(hit.Parent.Name) ~= nil then
if target.TeamColor == script.Parent.creator.Value.TeamColor then
humanoid:TakeDamage(teamD)
elseif target.TeamColor ~= script.Parent.creator.Value.TeamColor then
humanoid:TakeDamage(damage)
end
end
end
if hit.Name == "Head" then damage = damage * 3 end
humanoid:TakeDamage(damage)
else
end
ball:remove()
end
function tagHumanoid(humanoid)
-- todo: make tag expire
local tag = ball:findFirstChild("creator")
if tag ~= nil then
local new_tag = tag:clone()
new_tag.Parent = humanoid
game.Debris:AddItem(new_tag, 1)
end
end
wait(5)
ball:destroy()
end
wait(5)
ball:remove()
The script runs a function which test whether the target's TeamColor is the TeamColor of the shooter (creator). But instead of doing that it does not deal damage at all. If you find any problem please let me know what errors I have made. Thank you for reading :)

1 comment
Thank you for helping but my question has already been solved :)