LinearVelocity laggy and buggy on client side

I’m a beginner scripter and this topic may seem silly to you but I really need help

  1. What do you want to achieve? I want to fix linearvelocity

  2. What is the issue? I made linearvelocity for enemy’s character (humanoidrootpart) on client side and its not working

  3. What solutions have you tried so far? I did look for solutions on CreatorHub and I actually gave the player the networkownership for enemy’s humanoidrootpart but it didnt help

So I’m making combat system and when player attacks enemy the player’s client creates a LinearVelocity and Attachment for the enemy’s character. The problem is linearvelocity not working (or working very laggy with big delay and for few seconds) when I creating it and putting in enemy’s humanoidrootpart

local Attachment = Instance.new("Attachment")
Attachment.Parent = Character.HumanoidRootPart

	local LinearVelocity = Instance.new("LinearVelocity")
	LinearVelocity.Parent = Character.HumanoidRootPart

	LinearVelocity.MaxForce = 999999999999
	LinearVelocity.Attachment0 = Attachment
	LinearVelocity.VectorVelocity = (Player.Character.HumanoidRootPart.CFrame.LookVector * 60)
	task.delay(0.2,function()
		LinearVelocity:Destroy()
		Attachment:Destroy()
	end)

:up_arrow: this is client-side code :up_arrow:

To begin, I would heavily advise against handing the target’s network ownership to the attacking player. This would allow the attacking client to freely manipulate the target’s position. I’m not quite sure how this would even behave as I have never done combat this way, but you’d be better off either:

  1. Not setting network ownership at all
  2. Setting network ownership to nil, allowing the server to take over (also comes with the benefit of entirely preventing physics manipulation, though it will appear choppy to the target if they were moving beforehand)

Also, whenever you’re dealing with physics replication (when the network ownership doesn’t match the current context, it being the server or the specific client), always expect a delay. Physics replication frequency is set to just 15Hz. Expect even more delay if the current context is some client, and the network owner is another client.

This is kind of, not resolvable? You’d have to handle character replication yourself (fortunately for you, there are open-source modules available). If you don’t feel like doing all that, try to mask the delay using VFX.

Thanks for the response! But I’m actually even more confused. My code works without any delays when I run it on the server. I thought that running it on the client would make it smoother, but it actually makes it even worse.

I have never done combat this way

So you made a combat system but in a different way? Did you do it on the server side?

The way I do it is, whenever the target has velocity applied to them, their network ownership is transferred to the server. This ensures that the simulation is consistent for everyone, while also entirely eliminating the possibility of people cheating their way out of combos. That being said, I do make use of manually-done character replication so I can get away with this without introducing perceptible delays for the target.

If the server is the one simulating physics, the server state is calculated immediately and THEN replicated to clients, which minimizes the delay.

If some client is simulating physics, the client state is calculated immediately and then replicated to the server, which, in turn, replicates it to other clients. This introduces a second layer of replication which is dependent on the network owner’s ping.