My issue: I have made a soccer ball in my game, but everytime I kick it, it does what it’s supposed to do, but it sometimes stops in place for half a second then continues.
My script:
local Services = {
Players = game:GetService("Players"),
Debris = game:GetService("Debris")
}
local Settings = {
Kick_Cooldown = 0.5,
Kick_Height = 0.1
}
local Ball = script.Parent
local KickSound = Ball:WaitForChild("Kick")
local IgnoreTable = {}
Ball.Touched:Connect(function(hit)
local Character = hit.Parent
local isPlayer = Character:FindFirstChild("Humanoid")
if not isPlayer then
return
end
if Character then
if isPlayer then
if hit.Parent.Name == "GoalkeeperRed" then return end
if hit.Parent.Name == "GoalkeeperBlue" then return end
if hit.Parent.Name == "Referee" then return end
script.Parent.Value.Value = hit.Parent
local Kick_Force = Character.Power.Value
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 = Root.CFrame.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 * Kick_Force) + Vector3.new(0, Kick_Force *Settings.Kick_Height, 0)
Services.Debris:AddItem(Velocity, 0.2)
KickSound:Play()
Kick_Force = 20
end
end
end)