Advertisement
Anukun_Lucifer

RunScript

Oct 25th, 2024
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.64 KB | Gaming | 0 0
  1. -- ตั้งค่าความเร็วเดินปกติและความเร็วเมื่อวิ่ง
  2. local NormalWalkSpeed = 8
  3. local SprintSpeed = 12
  4. local CameraEffect = true  -- ตัวแปรควบคุมว่าเอฟเฟกต์กล้องจะถูกใช้งานหรือไม่
  5.  
  6. -- เรียกใช้งาน ContextActionService เพื่อใช้ปุ่มในการควบคุม
  7. local cas = game:GetService("ContextActionService")
  8. local Leftc = Enum.KeyCode.LeftControl  -- ปุ่มซ้ายควบคุมการวิ่ง
  9. local RightC = Enum.KeyCode.RightControl -- ปุ่มขวาควบคุมการวิ่ง
  10. local player = game:GetService("Players").LocalPlayer
  11. local char = player.Character or player.CharacterAdded:Wait()
  12. local Humanoid = char:WaitForChild("Humanoid")  -- เรียกตัวละครผู้เล่น
  13.  
  14. -- ตั้งค่ากล้องและเรียกใช้ TweenService เพื่อให้เกิดการเคลื่อนไหวกล้องแบบนุ่มนวล
  15. local Camera = game.Workspace.CurrentCamera
  16. local TweenService = game:GetService("TweenService")
  17. local UIS = game:GetService("UserInputService")
  18.  
  19. -- ฟังก์ชันนี้จะทำงานเมื่อมีการกดปุ่ม LeftShift เพื่อเพิ่มความเร็ววิ่งและเปลี่ยน FieldOfView ของกล้อง
  20. UIS.InputBegan:Connect(function(key, gameProcessed)
  21.     if gameProcessed then return end  -- หยุดการทำงานถ้าเป็นอินพุตที่ถูกประมวลผลแล้ว
  22.     if key.KeyCode == Enum.KeyCode.LeftShift then
  23.         if CameraEffect == true then
  24.             -- เพิ่ม FieldOfView ของกล้องเพื่อให้เกิดเอฟเฟกต์การวิ่ง
  25.             TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 80}):Play()
  26.         end
  27.         Humanoid.WalkSpeed = SprintSpeed  -- ตั้งความเร็วการวิ่ง
  28.     end
  29. end)
  30.  
  31. -- ฟังก์ชันนี้จะทำงานเมื่อปล่อยปุ่ม LeftShift เพื่อลดความเร็วกลับไปที่ค่าเดินปกติและรีเซ็ต FieldOfView ของกล้อง
  32. UIS.InputEnded:Connect(function(key, gameProcessed)
  33.     if gameProcessed then return end
  34.     if key.KeyCode == Enum.KeyCode.LeftShift then
  35.         if CameraEffect == true then
  36.             -- ลด FieldOfView ของกล้องกลับไปที่ค่าเริ่มต้น
  37.             TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 70}):Play()
  38.         end
  39.         Humanoid.WalkSpeed = NormalWalkSpeed  -- ตั้งความเร็วการเดินปกติ
  40.     end
  41. end)
  42.  
  43. --------------------------------------------------- ปุ่มวิ่งสำหรับมือถือ
  44.  
  45. -- ฟังก์ชัน handleContext สำหรับการวิ่งในมือถือ เมื่อต้องการเริ่มหรือหยุดวิ่ง
  46. local function handleContext(name, state, input)
  47.     if state == Enum.UserInputState.Begin then
  48.         if CameraEffect == true then
  49.             -- เพิ่ม FieldOfView ของกล้องเมื่อเริ่มวิ่ง
  50.             TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 80}):Play()
  51.         end
  52.         Humanoid.WalkSpeed = SprintSpeed  -- เพิ่มความเร็วการวิ่ง
  53.     else
  54.         if CameraEffect == true then
  55.             -- ลด FieldOfView ของกล้องเมื่อหยุดวิ่ง
  56.             TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 70}):Play()
  57.         end
  58.         Humanoid.WalkSpeed = NormalWalkSpeed  -- ลดความเร็วกลับเป็นค่าเดินปกติ
  59.     end
  60. end
  61.  
  62. -- ผูกฟังก์ชันการวิ่งกับปุ่มควบคุม และตั้งค่าตำแหน่งและขนาดของปุ่มในอินเตอร์เฟส
  63. cas:BindAction("วิ่ง", handleContext, true, Leftc, RightC)
  64. cas:SetPosition("วิ่ง", UDim2.new(.2, 0, .5, 0))  -- กำหนดตำแหน่งปุ่ม
  65. cas:SetTitle("วิ่ง", "วิ่ง")  -- ตั้งชื่อปุ่มให้แสดงว่า "วิ่ง"
  66. cas:GetButton("วิ่ง").Size = UDim2.new(.3, 0, .3, 0)  -- กำหนดขนาดของปุ่ม
  67.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement