▲ 0 r/lua
Help me fix this code, I'm trying to make a roblox game but I can't fix the delay of the ball
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ball = workspace:WaitForChild("Ball")
local RANGE = 4
local FRONT_DISTANCE = 3
RunService.Heartbeat:Connect(function()
for \_, player in pairs(Players:GetPlayers()) do
local char = player.Character
if char and char:FindFirstChild("HumanoidRootPart") then
I'm trying to make a football game in roblox but I cant make the ball stay infront it is always delayed, plss help me...
local hrp = char.HumanoidRootPart
local distance = (hrp.Position - ball.Position).Magnitude
if distance < RANGE then
local forward = hrp.CFrame.LookVector
-- target position in front of player (slightly on ground level)
local target = (hrp.Position + forward * FRONT_DISTANCE)
target = Vector3.new(target.X, ball.Position.Y, target.Z)
-- soft move instead of force push
ball.Position = ball.Position:Lerp(target, .5)
end
end
end
end)
u/Inevitable_Result345 — 17 days ago