Hi Devforum,
I made a script where when you kick or dribble a ball, it changes network ownership of that ball and such.
However, the hit detection is very laggy/unoptimized. I was wondering if anyone could help me fix this inaccuracy with that, I’ll show a video of what I mean.
Here, you can see how Player 1 passed it to Player 2, and Player 2 only landed 1 kick despite the ball going straight through them multiple times. Not only that but with network ownership being buggy, the players seem to “react late”. I will provide a script for you.
This is a server script from a remote event:
if data.Action == "Dribble" then
ball:SetNetworkOwner()
ball:SetNetworkOwner(player)
BallHandlerModule.changeConfiguration(ball, {
["Posession"] = player.Name
})
BallHandlerModule.Dribble(data)
elseif data.Action == "Shoot" then
-- ball:SetNetworkOwner()
BallHandlerModule.changeConfiguration(ball, {
["Posession"] = ""
})
BallHandlerModule.Shoot(data)
end
Now this script is the functions that are passed on the server:
function BallHandlerModule.Dribble(data)
local ball = data.Ball
local action = data.Action
local direction
if data.Direction then
direction = data.Direction
end
ball.AssemblyLinearVelocity = Vector3.new()
ball.AssemblyAngularVelocity = Vector3.new()
ball.Velocity = Vector3.new(0,0,0)
-- print(direction)
if action == "Dribble" then
if ball:FindFirstChild("BodyVelocity") then
ball.BodyVelocity.Velocity = (direction * 25) + Vector3.new(0,100,0)
else
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = direction * 25
bv.Parent = ball
Debris:AddItem(bv, .1)
end
end
end
function BallHandlerModule.Shoot(data)
local cameraLookVector = data.CameraDirection
local shotPower = data.ShotPower
local ball = data.Ball
if cameraLookVector and shotPower then
if ball:FindFirstChild("BodyVelocity") then
ball.BodyVelocity.Velocity = cameraLookVector * shotPower
else
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = cameraLookVector * shotPower
bv.Parent = ball
Debris:AddItem(bv, .1)
end
end
end
Help would be much appreciated to make this more optimized!