My soccer ball bugs out when the network ownership switches from one player to another, and If you try hitting it sometimes it will completely ghost you or the ball will go in a completely different direction than you were aiming. Here’s my code:
local Players = game:GetService("Players")
local ball = script.Parent
local reactDecline = false
local function onTouched(otherPart: BasePart)
if reactDecline then
return
end
local character = otherPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local player = Players:GetPlayerFromCharacter(character)
ball:SetNetworkOwner(player)
ball.AssemblyLinearVelocity = Vector3.new() -- reset the ball's velocity for smoother performance???
local direction = (ball.Position - otherPart.Position).Unit
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Velocity = Vector3.new(direction.X, 0, direction.Z) * 25
bodyVelocity.Parent = ball
reactDecline = true
task.delay(.3, function()
bodyVelocity:Destroy()
end)
task.delay(.3, function()
reactDecline = false
end)
end
end
ball.Touched:Connect(onTouched)