Advertisement
Cakey3101

Control Script

Apr 15th, 2025 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3. local ContextActionService = game:GetService("ContextActionService")
  4.  
  5. local Player = Players.LocalPlayer
  6. local Character = Player.Character or Player.CharacterAdded:Wait()
  7.  
  8. local Jumping = false
  9. local LeftValue, RightValue = 0, 0
  10.  
  11. local function Left(ActionName, InputState)
  12.     if InputState == Enum.UserInputState.Begin then
  13.         LeftValue = 1
  14.     elseif InputState == Enum.UserInputState.End then
  15.         LeftValue = 0
  16.     end
  17. end
  18.  
  19. local function Right(ActionName, InputState)
  20.     if InputState == Enum.UserInputState.Begin then
  21.         RightValue = 1
  22.     elseif InputState == Enum.UserInputState.End then
  23.         RightValue = 0
  24.     end
  25. end
  26.  
  27. local function Jump(ActionName, InputState)
  28.     if InputState == Enum.UserInputState.Begin then
  29.         Jumping = true
  30.     elseif InputState == Enum.UserInputState.End then
  31.         Jumping = false
  32.     end
  33. end
  34.  
  35. local function Update()
  36.     if Character and Character:FindFirstChild("Humanoid") then
  37.         if Jumping then
  38.             Character.Humanoid.Jump = true
  39.         end
  40.         local MoveDirection = RightValue - LeftValue
  41.         Character.Humanoid:Move(Vector3.new(MoveDirection, 0, 0), false)
  42.     end
  43. end
  44.  
  45. RunService:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, Update)
  46.  
  47. ContextActionService:BindAction("Left", Left, true, "a", Enum.KeyCode.Left, Enum.KeyCode.DPadLeft)
  48. ContextActionService:BindAction("Right", Right, true, "d", Enum.KeyCode.Right, Enum.KeyCode.DPadRight)
  49. ContextActionService:BindAction("Jump", Jump, true, "w", Enum.KeyCode.Space, Enum.KeyCode.Up, Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA)
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement