I’m making a soccer game and I have a goal and I want it to so when the ball is in the goal it counts as a goal, everything works but sometimes the touch event simply doesn’t work and the ball roams freely inside of the goal. Here’s my script.
local goalB = workspace.GoalB
local goalA = workspace.GoalA
local Team1Value = game.ReplicatedStorage.Team1Value
local Team2Value = game.ReplicatedStorage.Team2Value
local ball = workspace.SoccerBall
local originalPosition = workspace.BallSpawn
local debounce = false
goalA.Touched:Connect(function(hit)
if hit == ball then
if not debounce then
debounce = true
Team1Value.Value = Team1Value.Value + 1
ball.Hitbox.Particle.Score:Emit()
wait(0.5)
ball.CFrame = originalPosition.CFrame
ball.Anchored = true
end
wait(1)
ball.Anchored = false
debounce = false
end
end)
goalB.Touched:Connect(function(hit)
if hit == ball then
if not debounce then
debounce = true
Team2Value.Value = Team2Value.Value + 1
ball.Hitbox.Particle.Score:Emit()
wait(0.5)
ball.CFrame = originalPosition.CFrame
ball.Anchored = true
end
wait(1)
ball.Anchored = false
debounce = false
end
end)
local goalB = workspace.GoalB
local goalA = workspace.GoalA
local Team1Value = game.ReplicatedStorage.Team1Value
local Team2Value = game.ReplicatedStorage.Team2Value
local ball = workspace.SoccerBall
local originalPosition = workspace.BallSpawn
local debounce = false
goalA.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit == ball then
Team1Value.Value = Team1Value.Value + 1
ball.Hitbox.Particle.Score:Emit()
wait(0.5)
ball.CFrame = originalPosition.CFrame
ball.Anchored = true
end
wait(1)
ball.Anchored = false
debounce = false
end
end)
goalB.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit == ball then
Team2Value.Value = Team2Value.Value + 1
ball.Hitbox.Particle.Score:Emit()
wait(0.5)
ball.CFrame = originalPosition.CFrame
ball.Anchored = true
end
wait(1)
ball.Anchored = false
debounce = false
end
end)
local goalB = workspace.GoalB
local goalA = workspace.GoalA
local Team1Value = game.ReplicatedStorage.Team1Value
local Team2Value = game.ReplicatedStorage.Team2Value
local ball = workspace.SoccerBall
local originalPosition = workspace.BallSpawn
local debounce = false
goalA.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit:FindFirstAncestor("SoccerBall") then
Team1Value.Value = Team1Value.Value + 1
ball.Hitbox.Particle.Score:Emit()
wait(0.5)
ball.CFrame = originalPosition.CFrame
ball.Anchored = true
end
wait(1)
ball.Anchored = false
debounce = false
end
end)
goalB.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit:FindFirstAncestor("SoccerBall") then
Team2Value.Value = Team2Value.Value + 1
ball.Hitbox.Particle.Score:Emit()
wait(0.5)
ball.CFrame = originalPosition.CFrame
ball.Anchored = true
end
wait(1)
ball.Anchored = false
debounce = false
end
end)