Advertisement
Tweak16

ROBLOX Scripting | Mobile Shift Lock

Jun 16th, 2020 (edited)
5,893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. -- Made by Tweakified, Neonblox Games
  2. -- Video: https://www.youtube.com/watch?v=4GcgE8Qj7QE
  3.  
  4. local UserInputService = game:GetService("UserInputService")
  5. local RunService = game:GetService("RunService")
  6.  
  7. local player = game.Players.LocalPlayer
  8. local PlayerGui = player:WaitForChild("PlayerGui")
  9.  
  10. local ScreenGui = script.Parent
  11. local MainFrame = ScreenGui:FindFirstChild("Frame")
  12. local ControllerButton = MainFrame:FindFirstChild("Controller"):FindFirstChild("ImageButton")
  13. local MiddleIconFrame = MainFrame:FindFirstChild("MiddleIcon")
  14.  
  15. local Active = false
  16.  
  17. if UserInputService.TouchEnabled == true then
  18.     MainFrame.Visible = true
  19.    
  20.     ControllerButton.MouseButton1Click:Connect(function()
  21.         Active = not Active
  22.         MiddleIconFrame.Visible = Active
  23.     end)
  24.    
  25.     local function MobileShiftLock()
  26.         if Active == true then
  27.             local char = player.Character
  28.             if char ~= nil then
  29.                 local Head = char:FindFirstChild("Head")
  30.                 local HumanoidRootPart = char:FindFirstChild("HumanoidRootPart")
  31.                 local Humanoid = char:FindFirstChild("Humanoid")
  32.                
  33.                 local Camera = workspace.CurrentCamera
  34.                 if HumanoidRootPart ~= nil and Humanoid.Sit == false then
  35.                     local LookVector = Camera.CFrame.LookVector
  36.                     HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0, math.atan2(-LookVector.X, -LookVector.Z), 0)
  37.                 end
  38.                 if Head ~= nil then
  39.                     local InFirstPerson = (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude
  40.                     InFirstPerson = (InFirstPerson<2) and (1.0-(InFirstPerson-0.5)/1.5) or 0
  41.                     if InFirstPerson < 0.5 then
  42.                         Camera.CFrame = Camera.CFrame * CFrame.new(1.75, 0, 0)
  43.                     end
  44.                 end
  45.             end
  46.         end
  47.     end
  48.     RunService:BindToRenderStep("MobileShiftLock", 201, MobileShiftLock)
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement