I’ve been working on a soccer game and I want my soccer ball to have a force on it when a player touches it.
Just a few weeks ago my soccer ball scripted worked fine when I tested it. I just tested my soccer ball now and it doesn’t move when I touch it.
I’ve checked if the ball was anchored and it isn’t. I looked on the dev forum I found some posts that somewhat correlates to my post but it didn’t help my problem.
I know that Body Movers are deprecated but they still worked when I included it in my script the last time I tested my soccer ball a few weeks ago.
This is what my script looks like:
local Services = {
Players = game:GetService("Players"),
Debris = game:GetService("Debris")
}
local Settings = { --Ball settings
Kick_Cooldown = 1,
Kick_Force = 100 --Force to be applied
}
local Ball = script.Parent
local KickSound = Ball:WaitForChild("Kick")
local IgnoreTable = {}
Ball.Touched:Connect(function(Part)
local Character = Part.Parent
if Character:FindFirstChild("Humanoid") then
script.Parent.Player.Value = Character.Name
end
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)