I’m trying to prevent players from the same team to “tackle” eachother in a soccer game, the script works but spams the console with errors
I have re-checked the code multiple times yet i cant tell what’s causing the error, it errors when i try to tackle someone that is the same team as me.
My code: (The prints are just there for debugging purposes).
Player.Character["Right Leg"].Touched:connect(function(hit)
if Kick == false then return end
local plrhit = game.Players:GetPlayerFromCharacter(hit.Parent)
if plrhit.TeamColor == Player.TeamColor then
print('Can\'t tackle teammates')
else
if hit.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.Trip_Player:FireServer(hit.Parent)
GameLogs:FireServer(hit.Parent.Name)
Kick = false
end
end
if hit.Name ~= "Ball" then return end
local force = Player.Character["Right Leg"].CFrame.lookVector * 35
local angle = Vector3.new(90000000000,100000,90000000000)
Kick = false
TM.ApplyForce(hit, angle, force, "Right Leg")
end)
Player.Character["Left Leg"].Touched:connect(function(hit)
if Kick == false then return end
local plrhit = game.Players:GetPlayerFromCharacter(hit.Parent)
if plrhit.TeamColor == Player.TeamColor then
print('Can\'t tackle teammates')
else
if hit.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.Trip_Player:FireServer(hit.Parent)
GameLogs:FireServer(hit.Parent.Name)
Kick = false
end
end
if hit.Name ~= "Ball" then return end
local force = Player.Character["Left Leg"].CFrame.lookVector * 35
local angle = Vector3.new(90000000000,100000,90000000000)
Kick = false
TM.ApplyForce(hit, angle, force, "Left Leg")
end)
Lines 117 & 136: (These are the lines that error out)
if plrhit.TeamColor == Player.TeamColor then