local ball = script.Parent local damage = 100 local hitt = false

function CanHit(player, humanoid) local p2 = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent) if p2 == nil then return true end if player.TeamColor ~= p2.TeamColor then return true end return false end

function Touched(hit)

local humanoid = hit.Parent:FindFirstChild("Humanoid")
local player = local player = game.Players:GetPlayerFromCharacter(Tool.Parent)

if hit.Parent:FindFirstChild("ForceField") ~= nil then
	return
		ball:Destroy()
end

if hit.CanCollide == true and humanoid == nil then
	ball.Anchored = true
	ball.CanCollide = true
	wait()
	ball:Destroy()
end

if hit.CanCollide == false and humanoid == nil then
	return
end

if humanoid ~= nil and humanoid == ball.creator.Value then
	return
end

if humanoid ~= nil and hitt == false and humanoid.Parent ~= ball.creator.Value.Character and CanHit(player, humanoid) then
	hitt = true
	ball.Anchored = true		
	ball.CanCollide = true
	tagHumanoid(humanoid)
	humanoid.Health = humanoid.Health - damage
	wait(0.2)
	untagHumanoid(humanoid)
	wait(1)
	ball:Destroy()
end

end

function tagHumanoid(humanoid) local tag = ball:FindFirstChild("creator") if tag ~= nil then local new_tag = tag:Clone() new_tag.Parent = humanoid end end

function untagHumanoid(humanoid) if humanoid ~= nil then local tag = humanoid:GetChildren() for i = 1, #tag do if tag[i].Name == "creator" then tag[i]:Destroy() end end end end

connection = ball.Touched:Connect(Touched)

wait(30) ball:Destroy()

I already tried many times to define a function like CanHit(player, humanoid), but it simply don't recognize the CanHit function to define the players team and stop them from tk, the gun simply stop killing when i put this function.