I’m trying to make a touch based soccer ball and it works by giving network ownership to player who touched it and then applying force, but when two players are constantly fighting for the ball the network ownership gets bad and it starts teleporting and keeps going in random directions on touch, any way to fix this?
script inside ball
local function onTouched(otherPart: BasePart)
if reactDecline.Value == true then
warn("React declined!")
return
end
local character = otherPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local player = Players:GetPlayerFromCharacter(character)
if player ~= owner.Value then
ball:SetNetworkOwner(player)
owner.Value = player
end
ReplicatedStorage.Remotes.Kick:FireClient(player, ball)
kickSound:Play()
reactDecline.Value = true
task.delay(0.3, function()
reactDecline.Value = false
end)
end
end
client script (to handle forces)
local function onClientEvent(ball: BasePart)
local direction = (ball.Position - humanoidRootPart.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) * 30
bodyVelocity.Parent = ball
task.delay(0.3, function()
bodyVelocity:Destroy()
end)
end