I am making a soccer game where you can obviously score goals. I have made a string value which saves the value of the last player that touched the ball and when someone scores it says that the last player that touched the ball has scored. But how can I do the same with assists (pass to the goalscorer)? I want to do it with StringValues.
local lasttouched = game.ReplicatedStorage.lastTouched
local GoalTouch = game.Workspace.GoalTouch
local GoalTouch2 = game.Workspace.GoalTouch2
local team1goal = 0
local team2goal = 0
Ball.Touched:Connect(function(player)
if not connection3 then
connection3 = true
if player.Parent ~= workspace and player.Name ~= "Pitch" and player.Name ~= "Model" then
if player.Parent.Parent == workspace then
lasttouched.Value = player.Parent.Name
end
if player.Parent.Parent.Parent == workspace then
lasttouched.Value= player.Parent.Parent.Name
end
end
end
wait(0.05)
connection3 = false
end)
GoalTouch.Touched:Connect(function(hit)
if hit.Name == "Ball" then
if not connection2 then
connection2 = true
print("GOAL")
team1goal += 1
Goal1.Value = team1goal
Goal2.Value = team2goal
end
wait(3)
connection2 = false
end
end)
GoalTouch2.Touched:Connect(function(hit)
if hit.Name == "Ball" then
if not connection then
connection = true
print("GOAL")
team2goal += 1
Goal1.Value = team1goal
Goal2.Value = team2goal
end
wait(3)
connection = false
end
end)