What do you want to achieve? Keep it simple and clear!
I want the ball to move smoothly whenever I apply force on it.
What is the issue? Include screenshots / videos if possible!
Well, It`s pretty laggy.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked for solutions, on the Dev Hub, but they all said to set the network owner to the player, but it will still be laggy for others and it’s really easy to exploit.
Here is my code :
hitbox:SetNetworkOwner(player)
hitbox.Parent.Ball:SetNetworkOwner(player)
local lv = Instance.new("BodyVelocity", hitbox.Parent.Ball)
lv.MaxForce = Vector3.new(10000,10000,10000)
if side == "Left" then
if players:GetPlayerFromCharacter(player.Character) and player.Character:FindFirstChild("HumanoidRootPart") then
if player.Character.HumanoidRootPart:FindFirstChild("BallWeld") then
player.Character.HumanoidRootPart.BallWeld:Destroy()
end
lv.Velocity = -hitbox.CFrame.RightVector * 50
end
else
if players:GetPlayerFromCharacter(player.Character) and player.Character:FindFirstChild("HumanoidRootPart") then
if player.Character.HumanoidRootPart:FindFirstChild("BallWeld") then
player.Character.HumanoidRootPart.BallWeld:Destroy()
end
lv.Velocity = hitbox.CFrame.RightVector * 50
end
end
game.Debris:AddItem(lv, .1)
wait(.5)
hitbox:SetNetworkOwner(nil)
hitbox.Parent.Ball:SetNetworkOwner(nil)
Anyways, Thank to anyone who can help me resolve this problem!
Sorry I misread lol, I removed that comment.
But yeah, using BodyMovers on parts that are Network Owned by a Client will cause lag. You should use the BodyMovers locally
You can use Part.AssemblyLinearVelocity to get the Velocity, or you can fire a RemoteEvent from Client > Server to let the server know. Though you will have to do some sanity checks to avoid exploits / abuse
AssemblyLinearVelocity just returns the Parts velocity in a Vector3 value
Eg
if the AssemblyLinearVelocity = Vector3.new(0,0,5) then it is moving 5 studs in the Z axis.
If you just make the ball owned by the ServerSetNetworkOwner(nil) then you can add a touched event in a server script and use Ball:ApplyImpulse( Vector3 ) to apply a force to the ball in the desired direction
EG:
Ball.Touched:connect(function(part)
local LookAt = CFrame.lookat(part.Position, ball.Position)
local Direction = LookAt.LookVector
local Force = 500
Ball:ApplyImpulse(Direction*Force)
end)