Touch team 1 and team 2

Hello, here I am programming a football game and I would like to make a touch, there are two teams team 1 and team 2, there is a red line which indicates the touch, I would like that when a person from team 1 kicks the ball and the ball crosses the red line, I would like the touch to be for team 2.

Then when team 2 kicks the ball and the ball crosses the red line, I would like the touch to be for team 1

EX :

A person from team 1 kicked and the ball crossed the red line, the touch and for team 2

                                                  ^^^^^^^^^^^^^^^^^^^^


A person from team 2 kicked and the ball crossed the red line, the touch and for team 1
^^^^^^^^^^^^^^^^^^^^

Help me please, Thanks.

did you assign the touch to a different part(team)?

maybe showing your script could allow us to see what is going on

I didn’t make a script because I don’t know how to script it

When a player kicks the ball, set a value to check which team touched it last. Once it hits the required destination, check if the value is team 1 or team 2.

Do you have the script? to help me please.

Sorry, I can’t write you a full script…

Is the script that long? Really ?

Please write me just a bit, help me are you there to help me?

Is it really that hard? Also the devforum isnt for spoonfeeding code, its to get help on your problems.

It’s not that it’s that hard, it’s just to get a glimpse of the code. then i finish it myself.

I don’t know how start my script.

line.Touched:Connect(function()

end)

use a touched function to detect when a ball touches.

You need to check if the ball is touching or else players can go on line and get points.

line.Touched:Connect(function(hit)
    if hit.Name == "Ball name here" then
        --Point system here
    end
end)

first you need to make sure that you at least have one Team
to create a Team you need to go to Teams (it should be in the explorer) and create a Team inside of it. Select the team that you’ve created and get to the properties tab and change the TeamColor property to the team color you want.
next make a script and write the following inside it

-- put this script inside the line
-- I explained things as much as I can

local line = script.Parent -- the line that detects the touching
local goal = workspace.Goal -- the goal or the part that changes in colors

local ball = workspace.Ball -- the ball

local function onScored(team) -- fires when a team scores a goal!
	-- do anything
	print(team.Name .. " scored!") -- this message should be in the output
end

local function onLineHit(hit) -- hit is the part that touched the line
	
	if hit == ball then
		
		local tag = ball:FindFirstChild("TeamTag") -- checks which team kicked the ball
		if tag then
			
			local team = game:GetService("Teams"):FindFirstChild(tag.Value)
			if team then
				goal.BrickColor = team.TeamColor
				onScored(team)
			end	
		end
		
	end
end

local function onBallHit(hit) -- hit is the part that touched the ball
	
	if game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then -- checks if it's a player
		
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		local team = player.Team
		
		local tag = ball:FindFirstChild("TeamTag")
		if tag then
			tag.Value = team.Name
		else
			local tag = Instance.new("StringValue", ball) -- creates a tag inside of the ball
			tag.Name = "TeamTag"
			
			tag.Value = team.Name
		end
		
	end
end

line.Touched:Connect(onLineHit)
ball.Touched:Connect(onBallHit)

Really thank you very much for your help.