Advertisement
BloxScript_Hub

CFrame Walkspeed | TESTING

Jul 7th, 2023
4,178
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 1 0
  1. local WALK_SPEED = 185 -- Adjust the walk speed as desired
  2.  
  3. local character = script.Parent
  4. if not character or not character:IsA("Model") or not character:FindFirstChild("Humanoid") then
  5.     return
  6. end
  7.  
  8. -- Variables
  9. local userInputService = game:GetService("UserInputService")
  10. local moveDirection = Vector3.new()
  11.  
  12. -- Function to handle the user input
  13. local function handleInput(input, isKeyDown)
  14.     if input.KeyCode == Enum.KeyCode.W then
  15.         moveDirection = Vector3.new(0, 0, -1)
  16.     elseif input.KeyCode == Enum.KeyCode.A then
  17.         moveDirection = Vector3.new(-1, 0, 0)
  18.     elseif input.KeyCode == Enum.KeyCode.S then
  19.         moveDirection = Vector3.new(0, 0, 1)
  20.     elseif input.KeyCode == Enum.KeyCode.D then
  21.         moveDirection = Vector3.new(1, 0, 0)
  22.     end
  23.  
  24.     character.Humanoid.WalkSpeed = isKeyDown and WALK_SPEED or 0
  25.  
  26.     character.Humanoid:MoveTo(character.HumanoidRootPart.Position + moveDirection)
  27. end
  28.  
  29. userInputService.InputBegan:Connect(function(input)
  30.     if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.A or
  31.         input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.D then
  32.         handleInput(input, true)
  33.     end
  34. end)
  35.  
  36. userInputService.InputEnded:Connect(function(input)
  37.     if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.A or
  38.         input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.D then
  39.         handleInput(input, false)
  40.     end
  41. end)
  42.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement