Hello, this is a repost because my last post about this wasnt giving too much information. I am making a roll script, that uses Linear Velocity to move the player. But the problem is that the linear velocity only looks smooth on the client. On the server and to other players, it looks like a teleport and is laggy.
https://medal.tv/games/roblox/clips/vsh4p3ErzUuc3/d13373YrOVt5?invite=cr-MSxqZ1gsODE2MTQ0ODEs - clip of it happening
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 am very confused on this problem so I need help. Also because of the fact that im inserting the Linear Velocity from the server? but its only not laggy on the client?