So I have been trying to make a goal script system that tp a ball when it enter the goals and also putting the velocity to zero so the ball doesn’t move after being unanchored but It somehow still move
local Goal1 = game.Workspace.BallSystem.Team1Goal
local Goal2 = game.Workspace.BallSystem.Team2Goal
local Audio = game.Workspace.BallSystem.Sifflet
local lastTimeFired = 0
local cooldown = 5
function onGoalTouched(otherPart)
local currentTime = tick()
if currentTime - lastTimeFired >= cooldown and otherPart.Name == "Ball" and otherPart:IsA("MeshPart") then
Audio:Play()
otherPart.Anchored = true
otherPart.Position = Vector3.new(-36.498, 3.475, 164.843)
otherPart.Velocity = Vector3.new(0, 0, 0)
game.Workspace.BallSystem.Ball.SoccerBallScript.Enabled = false
wait(7)
game.Workspace.BallSystem.Ball.SoccerBallScript.Enabled = true
otherPart.Anchored = false
lastTimeFired = currentTime
end
end
Goal1.Touched:Connect(onGoalTouched)
Goal2.Touched:Connect(onGoalTouched)
Ball script:
local Services = {
Players = game:GetService("Players"),
Debris = game:GetService("Debris")
}
local Settings = {
Kick_Cooldown = 1,
Kick_Force = 75
}
local Ball = script.Parent
local KickSound = Ball:WaitForChild("Kick")
local IgnoreTable = {}
Ball.Touched:Connect(function(Part)
local Character = Part.Parent
if not Character then
return
end
local Player = Services.Players:GetPlayerFromCharacter(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Root = Character:FindFirstChild("HumanoidRootPart")
if not Player or not Humanoid or Humanoid.Health <= 0 or not Root or table.find(IgnoreTable, Player) then
return
end
table.insert(IgnoreTable, Player)
delay(Settings.Kick_Cooldown, function()
if not Player then
return
end
local Position = table.find(IgnoreTable, Player)
if not Position then
return
end
table.remove(IgnoreTable, Position)
end)
local Direction = CFrame.lookAt(Root.Position, Ball.Position).LookVector
if Direction.Magnitude < 0.001 then
return
end
local Velocity = Instance.new("BodyVelocity")
Velocity.Parent = Ball
Velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
Velocity.Velocity = (Direction.Unit * Settings.Kick_Force) + Vector3.new(0, Settings.Kick_Force /1.05, 0)
Services.Debris:AddItem(Velocity, 0.2)
KickSound:Play()
end)
I really don’t know how to fix this as I don’t get any errors if anyone would help me I would really apreciate it!