LinearyVelocity lagging for clients in my game

I have been working on this melee system for aboutt 2 weeks and i cant figure out why the LinearyVelocity for the knockback of the melee lags on client but not on the server. If anyone knows an alternative to or fix to it please tell me

Video of it

Ive tried to make the force less but it doesnt really do anything.

    --Function that makes knockback
    local function Fling(Stat, target, vector)
		local StatRagdolled = Stat.Humanoid.Ragdolled
		local HRP = target.HumanoidRootPart
		if StatRagdolled.Value then
			local Velocity = Instance.new("LinearVelocity")
			Velocity.Parent = HRP
			Velocity.RelativeTo = Enum.ActuatorRelativeTo.World
			Velocity.Attachment0 = HRP.RootAttachment
			Velocity.VectorVelocity =  vector*Ragdoll.Force + Ragdoll.UpwardForce --Force is 20 and UpwardForce is Vector3.new(0, 50, 0) for people that want to know
			Velocity.MaxForce = math.huge
			game.Debris:AddItem(Velocity, .25)
		end
	end

This much code isn’t going to help us help you.

i cant figure out why the LinearyVelocity for the knockback of the melee lags on client but not on the server

It shouldn’t. Can you give an example of how you are doing this?

2 Likes

use bodyvelocity

bodyvelocity settings and the velocity in the clip was 65
server has full physics ownership of the npc in question
image

Ignore this; this is misinformed.

Do NOT use BodyVelocity, it’s deprecated.

@overflowed, you should switch your BodyVelocity to LinearVelocity. It’s the same thing, but one has support… the other does not.

It seems that LinearVelocity is quite laggy, and is a known issue that the Roblox team is attempting to fix.

Regarding the post; I don’t believe it’s your LinearVelocity at all. However; it could be creating multiple LinearVelocities at once… causing lag. I’d have a check to see if there’s a LinearVelocity on the player already.

--Function that makes knockback
local function Fling(Stat, target, vector)
	local StatRagdolled = Stat.Humanoid.Ragdolled
	local HRP = target.HumanoidRootPart
	if StatRagdolled.Value then
		if HRP:FindFirstChild("LinearVelocity") then return end
		local Velocity = Instance.new("LinearVelocity")
		Velocity.Parent = HRP
		Velocity.RelativeTo = Enum.ActuatorRelativeTo.World
		Velocity.Attachment0 = HRP.RootAttachment
		Velocity.VectorVelocity =  vector*Ragdoll.Force + Ragdoll.UpwardForce --Force is 20 and UpwardForce is Vector3.new(0, 50, 0) for people that want to know
		Velocity.MaxForce = math.huge
		game.Debris:AddItem(Velocity, .25)
	end
end

If you provide more code, I can try to figure out the cause of the spikes.

deprecated does not mean unusable and linearvelocity instances have a well documented history in this forum for having replication issues

I agree on what @overflowed said. There’s an currently an issue that causes this replication lag/delay. This has been an issue for a long time and there’s still no fix for it other than to use the previous body movers.

Edit: I decided to use body velocity for my system instead.
I dont believe its creating multiple, mostly because i added a debounce and it would damage the character more than once when it registered the hit. So far body velocity has worked a bit smoother but ill still send more code

With body velocity

Looks alot more smoother to client for some reason.

--[[This fires when the client sends a remote event telling the server that 
    it hit something(hit registration is client sided) and is where it calls the fling
    function
]]
local function HitFunc(HitPart, Position, Normal, Combo)
		if HitPart.Parent:FindFirstChild("Humanoid") then
			local CMulti = GSC(ComboMulties, Combo)
			local Direction = GSC(Ragdoll.Directions, Combo)
			local PowerValue = GSC(General.Power, Combo)
			local StunCMulti = GSC(Stun.ComboMulties, Combo)
			local HitHumanoid = HitPart.Parent:FindFirstChild("Humanoid")
			local function ragFunc(CharStat, IsHead)
				local Values = CharStat.Values
				local Resistance = Values.Resistance
				local function CanTrip()
					if PowerValue > Resistance.Trip.Value then
						return true
					else
						return false
					end
				end
				if Ragdoll.Enabled then
					if Ragdoll.RequiresHead then
						if IsHead then
							if PowerValue > Resistance.Trip.Value then
								CharStat.Humanoid.Ragdolled.Value = true
								if Stun.Enabled then
									StunModule.Stun(HitHumanoid, Stun.WalkSpeed, Stun.Duration*Stun.RagMulti*StunCMulti, CanTrip())
								end
							end
						end
					end
				else
					if Stun.Enabled then
						StunModule.Stun(HitHumanoid, Stun.WalkSpeed, Stun.Duration*StunCMulti, false)
					end
				end
			end
			if CanDamage and self.Hits[HitHumanoid.Parent.Name] == nil then --Creates a debounce only for that humanoid, might be the cause but im not sure.
				if HitPart == nil or HitPart.Parent == nil then return end
				self.Hits[HitHumanoid.Parent.Name] = true
				if MultipleHits.Enabled then 
					task.wait(MultipleHits._Delay)
					self.Hits[HitHumanoid.Parent.Name] = nil
				end
				local NewDamage = General.Damage
				if not Pierce.Enabled then
					CanDamage = false
				else
					CanDamage = true
				end
				local FlingVector
				local HitPlrStat = _G.GCS(HitHumanoid.Parent) --If your wondering what this is it just gets a folder from rep storage containing values like is the player ragdolled
				self.Settings:Hit(self.Tool, HitHumanoid, (HitPart.Position + Normal))
				local function SetComboVector(Type)
					if Type == "Front" then
						FlingVector = HRP.CFrame.LookVector
					elseif Type == "Back" then
						FlingVector = -HRP.CFrame.LookVector
					elseif Type == "Right" then
						FlingVector =  HRP.CFrame.RightVector
					elseif Type == "Left" then
						FlingVector =  -HRP.CFrame.RightVector
					elseif Type == "Up" then
						FlingVector =  HRP.CFrame.UpVector
					elseif Type == "Down" then
						FlingVector =  -HRP.CFrame.UpVector
					end
				end
				
				SetComboVector(Direction)
				Fling(HitPlrStat, HitHumanoid.Parent, FlingVector)
				CreateSoundEffect(HitSounds, ("HitSound"..Combo), HitPart)
				NewDamage = NewDamage*CMulti
				DamageModule.Normal(HitHumanoid, NewDamage*LimbMulties[HitPart.Name])
				if Bleed.Enabled then
					DamageModule.Bleed(HitHumanoid, Bleed.DamageTo, Bleed.Time, Bleed.Tick)
				end

				if HitPart.Name == "Head" then
					ragFunc(HitPlrStat, true)
				elseif HitPart.Name == "Torso" then
					ragFunc(HitPlrStat, false)
				elseif HitPart.Name == "Right Arm" then
					ragFunc(HitPlrStat, false)
				elseif HitPart.Name == "Left Arm" then
					ragFunc(HitPlrStat, false)
				elseif HitPart.Name == "Right Leg" then
					ragFunc(HitPlrStat, false)
				elseif HitPart.Name == "Left Leg" then
					ragFunc(HitPlrStat, false)
				end
			end
		else
			if CanDamage and self.Hits[HitPart.Name] == nil then
				if HitPart == nil or HitPart.Parent == nil then return end
				self.Hits[HitPart.Name] = true
				if MultipleHits.Enabled then
					task.wait(MultipleHits._Delay)
					self.Hits[HitPart.Name] = nil
				end
				
				local String = ("Crack"..Combo)
				local clonedCrack = MeleeEffects.HitParts:FindFirstChild(String):Clone()
				clonedCrack.Parent = workspace.Debris
				clonedCrack.CFrame = CFrame.new(Position, Position + Normal)
				CreateSoundEffect(MeleeSounds.Impacts, "Impact"..Combo, clonedCrack)
				game.Debris:AddItem(clonedCrack, 10)
			end
		end
		return
	end
1 Like

Im actually not sure i just assumed that it didnt lag on the server because the knockbacked character still reached the ground after getting flung eventually.
Basically how it works is that once the client detects a hit, it sends a remote telling it to fire HitFunc which does stuff to the player including knockback. It has a debounce to it so im not sure why its choppy/laggy.

I went ahead and did research, and it seems that LinearVelocity has many faults causing lag and that the system works on the feature that’s causing the lag.

Here’s a reponse to a post regarding the issue and doing it’s own test.

https://devforum.roblox.com/t/linearvelocity-is-absolute-garbage-cant-make-bug-reports/2880306/12

I’ve never had this issue before, so I’m unaware as to why others are but it’s best to use BodyVelocity until this is fixed.

Here's some sources regarding the issue.

https://devforum.roblox.com/t/linearvelocity-is-absolute-garbage-cant-make-bug-reports/2880306

A LinearVelocity Instance Causes the Massless Property to be Ignored

LinearVelocity unexpected behavior

4 Likes

That is interesting. Must be a recent bug, I remember using LinearVelocity just a few months ago and had no problems with it. Thanks for the info!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.