-
What do you want to achieve? Make the networkownership change seamless, moving it to server isn’t an option as that has its own problems that we can’t accept
-
What is the issue? The ball is having a slight delay until it is being replicated to other clients making it seem like the ball is teleporting
-
What solutions have you tried so far? Searched through the devforum, asked the MPS (probs one of the most important games in the soccer community) owner about the problem, tried changing RemoteEvents to RemoteFunctions, added cooldowns
It’s important to note that there are soccer games that work on the same principle ( Setting networkownership and adding forces to the ball on the client ), and the problem isn’t present there
Server:
local function IsBallInProximity(player : Player, Ball : BasePart, maxProximity : number) : boolean
local distance = player:DistanceFromCharacter(Ball.Position)
if player.Character and distance <= maxProximity then
return true
else
return false
end
end
Shoot.OnServerEvent:Connect(function(player : Player, Ball : BasePart)
if Ball:GetAttribute("Ignore") == true then return end
if IsBallInProximity(player, Ball, SoccerConfiguration.MaxDetectionRange) then
local oldOwner = Ball:GetNetworkOwner()
if oldOwner and oldOwner ~= player then
Ball:SetAttribute("Ignore", true)
task.delay(0.3, function()
Ball:SetAttribute("Ignore", false)
end)
end
Ball:SetNetworkOwner(player)
Ball:SetAttribute("LastPlayerHit", player.DisplayName)
local Sound = Ball:FindFirstChild("HitSound")
if Sound then
Sound:Play()
end
end
end)
Client:
ApplyForces = function(Ball : BasePart, Power : number, Angle : number, direction : Vector3 | nil, timeToDestroyForce : number | nil)
local Character = Player.Character
if not Character then return end
Shoot:FireServer(Ball)
Ball.AssemblyLinearVelocity = Vector3.new()
Ball.AssemblyAngularVelocity = Vector3.new()
ForceApplierInstance:ApplyForce(Ball, "BallReact", (((direction or Character.HumanoidRootPart.CFrame.lookVector) * Power) + (Character.HumanoidRootPart.CFrame.UpVector * Angle)), timeToDestroyForce or 0)
end,
ApplyForce Module:
local function OnForceAdded(forceObject, desiredForce : Vector3)
print(forceObject)
forceObject.Velocity = desiredForce
forceObject.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
end
function ForceApplier:ApplyForce(Object : BasePart, ForceName : string, desiredForceValue : Vector3, destroyTime : number)
if destroyTime == 0 then
Object:ApplyImpulse(desiredForceValue*Object:GetMass())
else
local desiredForceObject = Object:FindFirstChild(ForceName)
if not desiredForceObject then return end
if not self.Forces[Object] then
self.Forces[Object] = {}
end
local oldForce = self.Forces[Object][desiredForceObject]
if oldForce then
self:UnApplyForce(Object, desiredForceObject.Name)
end
self.Forces[Object][desiredForceObject] = tick() + destroyTime
OnForceAdded(desiredForceObject, desiredForceValue)
end
end
PS. The ball teleports more and more depending on the ball’s velocity, it isn’t so obvious on the video, but when you’re fighting for the ball with another player then it’s really frustrating