Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Author: 0xEB (maxbd, maxbd07, maxbd123)
- -- Special thanks to InvalidCo_de (GrundyCone) for informing me of "UserInputService.MouseBehavior" and "Enum.MouseBehavior.LockCenter."
- local options = {
- WalkSpeed = 100,
- HotKey = Enum.KeyCode.E
- }
- local UserInputService = game:GetService("UserInputService")
- local PAYER = game:GetService("Players").LocalPlayer
- local HUMANOID = PLAYER.Character:FindFirstChild("Humanoid") or PLAYER.Character:FindFirstChildOfClass("Humanoid")
- local ROOT = PLAYER.Character:FindFirstChild("HumanoidRootPart") or PLAYER.Character.PrimaryPart
- local vA = (options.WalkSpeed - HUMANOID.WalkSpeed) / 32
- local vB, vC, vD = false, false, {}
- HUMANOID.Running:Connect(function(pA)
- vB = (pA > 0) and true or false
- end)
- local function GetDirectionVector(pA, pB)
- local vA = Vector3.new(0, 0, 0)
- vA = vA + ((pB[1] == true) and pA.CFrame.LookVector or Vector3.new(0, 0, 0))
- vA = vA + ((pB[2] == true) and pA.CFrame:VectorToWorldSpace(Vector3.new(-1, 0, 0)) or Vector3.new(0, 0, 0))
- vA = vA + ((pB[3] == true) and pA.CFrame:VectorToWorldSpace(Vector3.new(0, 0, 1)) or Vector3.new(0, 0, 0))
- vA = vA + ((pB[4] == true) and pA.CFrame:VectorToWorldSpace(Vector3.new(1, 0, 0)) or Vector3.new(0, 0, 0))
- return vA
- end
- UserInputService.InputBegan:Connect(function(pA, pB)
- if pA.UserInputType == Enum.UserInputType.Keyboard and pB == false then
- if pA.KeyCode == options.HotKey then
- vC, vD = (vC == false) and true or false, {true, false, false, false}
- while vC == true and wait() do
- if UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
- ROOT.CFrame = ROOT.CFrame + ROOT.CFrame.LookVector * vA
- else
- ROOT.CFrame = ROOT.CFrame + GetDirectionVector(ROOT, vD) * vA
- end
- end
- end
- if vC == true then
- if pA.KeyCode == Enum.KeyCode.W then vD[1], vD[3] = true, false end
- if pA.KeyCode == Enum.KeyCode.A then vD[2], vD[4] = true, false end
- if pA.KeyCode == Enum.KeyCode.S then vD[3], vD[1] = true, false end
- if pA.KeyCode == Enum.KeyCode.D then vD[4], vD[2] = true, false end
- end
- end
- end)
- UserInputService.InputEnded:Connect(function(pA, pB)
- if pA.UserInputType == Enum.UserInputType.Keyboard and pB == false and vC == true then
- if pA.KeyCode == Enum.KeyCode.W then vD[1] = false end
- if pA.KeyCode == Enum.KeyCode.A then vD[2] = false end
- if pA.KeyCode == Enum.KeyCode.S then vD[3] = false end
- if pA.KeyCode == Enum.KeyCode.D then vD[4] = false end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment