Linear Velocity lagging players?

I have a roll script, I use a linear velocity to move the players. For the player, they are moving smooth. But if they see another player roll, they teleport. Im not sure why its doing this because Im adding the Linear Velocity from the server.

https://medal.tv/games/roblox/clips/vsh4p3ErzUuc3/d13373YrOVt5?invite=cr-MSxqZ1gsODE2MTQ0ODEs

Please write your code in lua format.

    local a = Instance.new("Attachment", char.HumanoidRootPart)
	a.Name = "A0"
	a.Orientation = Vector3.new(0, 0, 0)

	local lv = Instance.new("LinearVelocity", plr.Character.HumanoidRootPart)
	lv.MaxForce = 100000
	lv.RelativeTo = "Attachment0"
	lv.Attachment0 = char.HumanoidRootPart.A0
	lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
	lv.LineDirection = Vector3.new(1, 0, 0)
	lv.LineVelocity = -45
	char.Humanoid.JumpPower = 0
	char.Humanoid.WalkSpeed = 0

You have to send me a rbxl file so i can see if theres any code errors

can you show a video this is a very confusing error there isnt a code error in the code you have posted so theres just a lack of information

https://medal.tv/games/roblox/clips/vsh4p3ErzUuc3/d13373YrOVt5?invite=cr-MSxqZ1gsODE2MTQ0ODEs

im not exactly sure why its happening still because i would need to see more code but imma give some opinions.
you should put the local script into “startercharacterscripts”. this means when the game runs the script will be replicated into the players character so you can do script.Parent instead of Plr.Character to get the character

another thing is why dont u just up the humanoid movement speed briefly then set it back to sixteen

the reason why there is this lag is because the maxforce could be too high or it could be because its having trouble replicating to the server and maybe you want to make a server script that you fire by remote event to add boosts etc to the characters

there is a remote event to put the linear velocity in the players

local script

local UIS = game:GetService("UserInputService")
local keyStates = {}
local keysToTrack = { [Enum.KeyCode.A]=true, [Enum.KeyCode.D]=true, [Enum.KeyCode.W]=true, [Enum.KeyCode.S]=true }

UIS.InputBegan:Connect(function(inputObj, processed)
	if processed then return end
	if keysToTrack[inputObj.KeyCode] then
		keyStates[inputObj.KeyCode] = true
	end
	if inputObj.KeyCode == Enum.KeyCode.Q then
		if keyStates[Enum.KeyCode.A] then
			print("A")
			game.ReplicatedStorage.RemoteEvents.RollEvent:FireServer("Left")
		elseif keyStates[Enum.KeyCode.D] then
			game.ReplicatedStorage.RemoteEvents.RollEvent:FireServer("Right")
		elseif keyStates[Enum.KeyCode.W] then
			game.ReplicatedStorage.RemoteEvents.RollEvent:FireServer("Foward")
		elseif keyStates[Enum.KeyCode.S] then
			game.ReplicatedStorage.RemoteEvents.RollEvent:FireServer("Back")
		else
			game.ReplicatedStorage.RemoteEvents.RollEvent:FireServer("Back")
		end
	end	
end)

UIS.InputEnded:Connect(function(inputObj, processed)
	if keysToTrack[inputObj.KeyCode] then
		keyStates[inputObj.KeyCode] = false
	end
end)

server script

local cd = {}

game.ReplicatedStorage.RemoteEvents.RollEvent.OnServerEvent:Connect(function(plr, rolltype)
	if not table.find(cd, plr.Name) then
		table.insert(cd, plr.Name)
		cd[plr.Name] = false
	end

	if cd[plr.Name] == true then return end
	if plr.Character.Status:FindFirstChild("Stun") then return end
	if plr.Character.Status:FindFirstChild("M1") then return end
	if plr.Character.Status:FindFirstChild("Parry") then return end
	if plr.Character.Status:FindFirstChild("Roll") then return end
	cd[plr.Name] = true
	
	local char = plr.Character
	local humanoid = char.Humanoid
	
	humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
	
	if plr.Character.Status:FindFirstChild("Blocking") then
		plr.Character.Status.Blocking:Destroy()
		for i, v in pairs(plr.Character.Humanoid:FindFirstChild("Animator"):GetPlayingAnimationTracks()) do
			if v.Name == "VigilSwordBlock" then
				v:Stop()
				humanoid.WalkSpeed = 16
			end
		end
	end
	
	if rolltype == "Left" then
		
		-----------------------------------------------------
		
		local anim = game.ReplicatedStorage.Animations.LeftRoll
		local animloaded = humanoid:FindFirstChild("Animator"):LoadAnimation(anim)

		--animloaded:Play()
		local rollf = Instance.new("Folder", plr.Character.Status)
		rollf.Name = "Roll"

		local a = Instance.new("Attachment", char.HumanoidRootPart)
		a.Name = "A0"
		a.Orientation = Vector3.new(0, 0, 0)

		local lv = Instance.new("LinearVelocity", plr.Character.HumanoidRootPart)
		lv.MaxForce = 100000
		lv.RelativeTo = "Attachment0"
		lv.Attachment0 = char.HumanoidRootPart.A0
		lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
		lv.LineDirection = Vector3.new(1, 0, 0)
		lv.LineVelocity = -45
		char.Humanoid.JumpPower = 0
		char.Humanoid.WalkSpeed = 0
		if char.Status:FindFirstChild("Sprinting") then
			char.Status.Sprinting:Destroy()
		end
		
		local connect
		
		connect = char.Status.ChildRemoved:Connect(function(instance)
			if instance.Name == "Roll" then
				local anim2 = game.ReplicatedStorage.Animations.RollCancel
				local animloaded2 = humanoid:FindFirstChild("Animator"):LoadAnimation(anim2)
				animloaded2:Play()
				if plr.Character.HumanoidRootPart:FindFirstChild("LinearVelocity") then
					plr.Character.HumanoidRootPart.LinearVelocity:Destroy()
				end
				if plr.Character.HumanoidRootPart:FindFirstChild("A0") then
					plr.Character.HumanoidRootPart.A0:Destroy()
				end
				local rcf = Instance.new("Folder", plr.Character.Status)
				rcf.Name = "RollCancel"
				game.Debris:AddItem(rcf, 0.25)
				local rcif = Instance.new("Folder", plr.Character.Status)
				rcif.Name = "RCiFrames"
				game.Debris:AddItem(rcif, 0.25)
				char.Humanoid.JumpPower = 50
				char.Humanoid.WalkSpeed = plr.Stats.BaseWalkspeed.Value
				connect:Disconnect()
			end
		end)

		task.wait(0.04)

		local rollif = Instance.new("Folder", plr.Character.Status)
		rollif.Name = "RiFrames"

		task.wait(0.24)

		connect:Disconnect()
		
		if plr.Character.Status:FindFirstChild("RiFrames") then
			plr.Character.Status.RiFrames:Destroy()
		end

		if plr.Character.Status:FindFirstChild("Roll") then
			plr.Character.Status.Roll:Destroy()
		end
		if plr.Character.HumanoidRootPart:FindFirstChild("LinearVelocity") then
			plr.Character.HumanoidRootPart.LinearVelocity:Destroy()
		end
		if plr.Character.HumanoidRootPart:FindFirstChild("A0") then
			plr.Character.HumanoidRootPart.A0:Destroy()
		end
		char.Humanoid.JumpPower = 50
		char.Humanoid.WalkSpeed = plr.Stats.BaseWalkspeed.Value
		
	elseif rolltype == "Right" then
		
		-----------------------------------------------------
		
		local anim = game.ReplicatedStorage.Animations.LeftRoll
		local animloaded = humanoid:FindFirstChild("Animator"):LoadAnimation(anim)

		--animloaded:Play()
		local rollf = Instance.new("Folder", plr.Character.Status)
		rollf.Name = "Roll"

		local a = Instance.new("Attachment", char.HumanoidRootPart)
		a.Name = "A0"
		a.Orientation = Vector3.new(0, 0, 0)

		local lv = Instance.new("LinearVelocity", plr.Character.HumanoidRootPart)
		lv.MaxForce = 100000
		lv.RelativeTo = "Attachment0"
		lv.Attachment0 = char.HumanoidRootPart.A0
		lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
		lv.LineDirection = Vector3.new(1, 0, 0)
		lv.LineVelocity = 45
		char.Humanoid.JumpPower = 0
		char.Humanoid.WalkSpeed = 0
		if char.Status:FindFirstChild("Sprinting") then
			char.Status.Sprinting:Destroy()
		end

		local connect

		connect = char.Status.ChildRemoved:Connect(function(instance)
			if instance.Name == "Roll" then
				local anim2 = game.ReplicatedStorage.Animations.RollCancel
				local animloaded2 = humanoid:FindFirstChild("Animator"):LoadAnimation(anim2)
				animloaded2:Play()
				if plr.Character.HumanoidRootPart:FindFirstChild("LinearVelocity") then
					plr.Character.HumanoidRootPart.LinearVelocity:Destroy()
				end
				if plr.Character.HumanoidRootPart:FindFirstChild("A0") then
					plr.Character.HumanoidRootPart.A0:Destroy()
				end
				local rcf = Instance.new("Folder", plr.Character.Status)
				rcf.Name = "RollCancel"
				game.Debris:AddItem(rcf, 0.25)
				local rcif = Instance.new("Folder", plr.Character.Status)
				rcif.Name = "RCiFrames"
				game.Debris:AddItem(rcif, 0.25)
				char.Humanoid.JumpPower = 50
				char.Humanoid.WalkSpeed = plr.Stats.BaseWalkspeed.Value
				connect:Disconnect()
			end
		end)

		task.wait(0.04)

		local rollif = Instance.new("Folder", plr.Character.Status)
		rollif.Name = "RiFrames"

		task.wait(0.24)
		
		connect:Disconnect()

		if plr.Character.Status:FindFirstChild("RiFrames") then
			plr.Character.Status.RiFrames:Destroy()
		end

		if plr.Character.Status:FindFirstChild("Roll") then
			plr.Character.Status.Roll:Destroy()
		end
		if plr.Character.HumanoidRootPart:FindFirstChild("LinearVelocity") then
			plr.Character.HumanoidRootPart.LinearVelocity:Destroy()
		end
		if plr.Character.HumanoidRootPart:FindFirstChild("A0") then
			plr.Character.HumanoidRootPart.A0:Destroy()
		end
		
		char.Humanoid.JumpPower = 50
		char.Humanoid.WalkSpeed = plr.Stats.BaseWalkspeed.Value
		
	elseif rolltype == "Foward" then
		
		-----------------------------------------------------
		
		local anim = game.ReplicatedStorage.Animations.LeftRoll
		local animloaded = humanoid:FindFirstChild("Animator"):LoadAnimation(anim)

		--animloaded:Play()
		local rollf = Instance.new("Folder", plr.Character.Status)
		rollf.Name = "Roll"
		
		local a = Instance.new("Attachment", char.HumanoidRootPart)
		a.Name = "A0"
		a.Orientation = Vector3.new(0, -90, 0)

		local lv = Instance.new("LinearVelocity", plr.Character.HumanoidRootPart)
		lv.MaxForce = 100000
		lv.RelativeTo = "Attachment0"
		lv.Attachment0 = char.HumanoidRootPart.A0
		lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
		lv.LineDirection = Vector3.new(1, 0, 0)
		lv.LineVelocity = -45
		char.Humanoid.JumpPower = 0
		char.Humanoid.WalkSpeed = 0
		if char.Status:FindFirstChild("Sprinting") then
			char.Status.Sprinting:Destroy()
		end
		
		

		local connect

		connect = char.Status.ChildRemoved:Connect(function(instance)
			if instance.Name == "Roll" then
				local anim2 = game.ReplicatedStorage.Animations.RollCancel
				local animloaded2 = humanoid:FindFirstChild("Animator"):LoadAnimation(anim2)
				animloaded2:Play()
				if plr.Character.HumanoidRootPart:FindFirstChild("LinearVelocity") then
					plr.Character.HumanoidRootPart.LinearVelocity:Destroy()
				end
				if plr.Character.HumanoidRootPart:FindFirstChild("A0") then
					plr.Character.HumanoidRootPart.A0:Destroy()
				end
				local rcf = Instance.new("Folder", plr.Character.Status)
				rcf.Name = "RollCancel"
				game.Debris:AddItem(rcf, 0.25)
				local rcif = Instance.new("Folder", plr.Character.Status)
				rcif.Name = "RCiFrames"
				game.Debris:AddItem(rcif, 0.25)
				char.Humanoid.JumpPower = 50
				char.Humanoid.WalkSpeed = plr.Stats.BaseWalkspeed.Value
				connect:Disconnect()
			end
		end)
		
		task.wait(0.04)

		local rollif = Instance.new("Folder", plr.Character.Status)
		rollif.Name = "RiFrames"

		task.wait(0.24)

		connect:Disconnect()
		
		if plr.Character.Status:FindFirstChild("RiFrames") then
			plr.Character.Status.RiFrames:Destroy()
		end
		
		if plr.Character.Status:FindFirstChild("Roll") then
			plr.Character.Status.Roll:Destroy()
		end
		if plr.Character.HumanoidRootPart:FindFirstChild("LinearVelocity") then
			plr.Character.HumanoidRootPart.LinearVelocity:Destroy()
		end
		if plr.Character.HumanoidRootPart:FindFirstChild("A0") then
			plr.Character.HumanoidRootPart.A0:Destroy()
		end
		
		char.Humanoid.JumpPower = 50
		char.Humanoid.WalkSpeed = plr.Stats.BaseWalkspeed.Value
		
	elseif rolltype == "Back" then
		
		-----------------------------------------------------
		
		local anim = game.ReplicatedStorage.Animations.LeftRoll
		local animloaded = humanoid:FindFirstChild("Animator"):LoadAnimation(anim)

		--animloaded:Play()
		local rollf = Instance.new("Folder", plr.Character.Status)
		rollf.Name = "Roll"

		local a = Instance.new("Attachment", char.HumanoidRootPart)
		a.Name = "A0"
		a.Orientation = Vector3.new(0, -90, 0)

		local lv = Instance.new("LinearVelocity", plr.Character.HumanoidRootPart)
		lv.MaxForce = 100000
		lv.RelativeTo = "Attachment0"
		lv.Attachment0 = char.HumanoidRootPart.A0
		lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
		lv.LineDirection = Vector3.new(1, 0, 0)
		lv.LineVelocity = 45
		char.Humanoid.JumpPower = 0
		char.Humanoid.WalkSpeed = 0
		if char.Status:FindFirstChild("Sprinting") then
			char.Status.Sprinting:Destroy()
		end

		local connect

		connect = char.Status.ChildRemoved:Connect(function(instance)
			if instance.Name == "Roll" then
				local anim2 = game.ReplicatedStorage.Animations.RollCancel
				local animloaded2 = humanoid:FindFirstChild("Animator"):LoadAnimation(anim2)
				animloaded2:Play()
				if plr.Character.HumanoidRootPart:FindFirstChild("LinearVelocity") then
					plr.Character.HumanoidRootPart.LinearVelocity:Destroy()
				end
				if plr.Character.HumanoidRootPart:FindFirstChild("A0") then
					plr.Character.HumanoidRootPart.A0:Destroy()
				end
				local rcf = Instance.new("Folder", plr.Character.Status)
				rcf.Name = "RollCancel"
				game.Debris:AddItem(rcf, 0.25)
				local rcif = Instance.new("Folder", plr.Character.Status)
				rcif.Name = "RCiFrames"
				game.Debris:AddItem(rcif, 0.25)
				char.Humanoid.JumpPower = 50
				char.Humanoid.WalkSpeed = plr.Stats.BaseWalkspeed.Value
				connect:Disconnect()
			end
		end)
		
		task.wait(0.04)
		
		local rollif = Instance.new("Folder", plr.Character.Status)
		rollif.Name = "RiFrames"
		
		task.wait(0.24)
		
		connect:Disconnect()
		
		if plr.Character.Status:FindFirstChild("RiFrames") then
			plr.Character.Status.RiFrames:Destroy()
		end
		if plr.Character.Status:FindFirstChild("Roll") then
			plr.Character.Status.Roll:Destroy()
		end
		if plr.Character.HumanoidRootPart:FindFirstChild("LinearVelocity") then
			plr.Character.HumanoidRootPart.LinearVelocity:Destroy()
		end
		if plr.Character.HumanoidRootPart:FindFirstChild("A0") then
			plr.Character.HumanoidRootPart.A0:Destroy()
		end
		
		char.Humanoid.JumpPower = 50
		char.Humanoid.WalkSpeed = plr.Stats.BaseWalkspeed.Value
		
	end
	
	task.wait(1.8)
    cd[plr.Name] = false
end)

I was doing some testing, it looks like it is only laggy on the server?? but on the client its smooth

the weird thing is that im putting it in the players character from the server

local keysToTrack = { [Enum.KeyCode.A]=false, [Enum.KeyCode.D]=false, [Enum.KeyCode.W]=f,alse [Enum.KeyCode.S]=false }

you want the keys to track to be initalized to false because atm the code thinks all the keys are being pressed until the key is used and released

i would recommend switching from adding a force into the player to using tweenservice to make the player smoothly dash forward TweenService example to forward dash:

local TweenService = game:GetService("TweenService")
local HumanoidRootPart = game.Players.LocalPlayer.Character.HumanoidRootPart
local NumberOfStudsToDash = 5
local SecDurationOfDash = 1
local GoalPosition = (HumanoidRootPart.CFrame.LookVector)*NumberOfStudsToDash
TweenService:Create(HumanoidRootPart, TweenInfo.new(SecDurationOfDash, Enum.EasingStyle.Linear), {Position = GoalPosition}):Play()

it may be a little complicated but i have broken it down into many readable variables this method would run a lot smoother i believe and would work nicely partnered with an animation
to make the character dash in other directions you would get vectors from the characters “HumanoidRootPart” CFrame such as

CFrame.RightVector --to get the vector going right of the character
-(CFrame.RightVector) --to get the vector going left of the character
CFrame.LookVector -- to get the vector going forwards of the character
-(CFrame.LookVector )-- to get the vector going backwards of the character

additionally there is Cframe.UpVector but that doesnt matter in this case i believe i have made it clear enough how they work

sorry this doesnt solve your problem but it is a great alternative and here is a great page on the type of tweening styles there are: EasingStyle

1 Like

ill try these out

(i need more characters)

i know im kinda late but i faced this issue too and after some research i found out that velocity needs to be on client to be without this lags(for some reason roblox servers cant handle velocity physics that smooth)