| local boost = 4
|
| local sprint = 8
|
|
|
| local players = game:GetService("Players")
|
| local runservice = game:GetService("RunService")
|
| local uis = game:GetService("UserInputService")
|
| local player = players.LocalPlayer
|
|
|
| local hb_conn
|
| local lv
|
| local att
|
| local sprinting = false
|
|
|
| local function teardown()
|
| if hb_conn then hb_conn:Disconnect() hb_conn = nil end
|
| if lv then lv:Destroy() lv = nil end
|
| if att and att:GetAttribute("_lv_created") then att:Destroy() end
|
| att = nil
|
| end
|
|
|
| local function setup(char)
|
| teardown()
|
| local hrp = char:WaitForChild("HumanoidRootPart")
|
| local hum = char:WaitForChild("Humanoid")
|
|
|
| att = hrp:FindFirstChildOfClass("Attachment")
|
| if not att then
|
| att = Instance.new("Attachment")
|
| att.Name = "lv_att"
|
| att:SetAttribute("_lv_created", true)
|
| att.Parent = hrp
|
| end
|
|
|
| lv = Instance.new("LinearVelocity")
|
| lv.Attachment0 = att
|
| lv.RelativeTo = Enum.ActuatorRelativeTo.World
|
| lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
|
| lv.ForceLimitMode = Enum.ForceLimitMode.Magnitude
|
| lv.PrimaryTangentAxis = Vector3.new(1,0,0)
|
| lv.SecondaryTangentAxis = Vector3.new(0,0,1)
|
| lv.PlaneVelocity = Vector2.zero
|
| lv.MaxForce = hrp.AssemblyMass * 4000
|
| lv.Enabled = false
|
| lv.Parent = hrp
|
|
|
| hb_conn = runservice.Heartbeat:Connect(function()
|
| if not hum or hum.Health <= 0 then if lv.Enabled then lv.Enabled = false end return end
|
|
|
| local dir = hum.MoveDirection
|
| dir = Vector3.new(dir.X, 0, dir.Z)
|
| if dir.Magnitude < 1e-3 then
|
| if lv.Enabled then lv.Enabled = false end
|
| return
|
| end
|
|
|
| local target_speed = (hum.WalkSpeed or 16) + (sprinting and sprint or boost)
|
| local desired = dir.Unit * target_speed
|
|
|
| lv.PlaneVelocity = Vector2.new(desired.X, desired.Z)
|
| lv.MaxForce = hrp.AssemblyMass * 4000
|
| if not lv.Enabled then lv.Enabled = true end
|
| end)
|
| end
|
|
|
| if player.Character then setup(player.Character) end
|
| player.CharacterAdded:Connect(setup)
|
|
|
| uis.InputBegan:Connect(function(input, gp)
|
| if gp then return end
|
| if input.KeyCode == Enum.KeyCode.LeftShift then sprinting = true end
|
| end)
|
|
|
| uis.InputEnded:Connect(function(input, gp)
|
| if gp then return end
|
| if input.KeyCode == Enum.KeyCode.LeftShift then sprinting = false end
|
| end)
|