Advertisement
DaDogeDevelopment

Mobile shift lock

Jun 7th, 2023
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. --Scripted by funwolf7
  2.  
  3. --Turn this to true to make the shift lock cursor thing appear at the center.
  4. local SHOW_CENTER_CURSOR = true
  5.  
  6. ------------------------------------------------------------------------
  7. --Actual script starts here. I don't reccomend modifying anything past this point.
  8.  
  9. local UserInputService = game:GetService("UserInputService")
  10. local RunService = game:GetService("RunService")
  11.  
  12. local Player = game.Players.LocalPlayer
  13.  
  14. local IsMobile = UserInputService.TouchEnabled --Is true if on mobile.
  15.  
  16. if IsMobile then --Only does things if it's on mobile. 
  17.     --Create the gui.
  18.     local SHIFT_LOCK_OFF = 'rbxasset://textures/ui/mouseLock_off.png'
  19.     local SHIFT_LOCK_ON = 'rbxasset://textures/ui/mouseLock_on.png'
  20.     local SHIFT_LOCK_CURSOR = 'rbxasset://textures/MouseLockedCursor.png'
  21.    
  22.     local frame = Instance.new('Frame')
  23.     frame.Name = "BottomLeftControl"
  24.     frame.Size = UDim2.new(.1, 0, .1, 0)
  25.     frame.Position = UDim2.new(1, 0, 1, 0)
  26.     frame.AnchorPoint = Vector2.new(1,1)
  27.     frame.BackgroundTransparency = 1
  28.     frame.ZIndex = 10
  29.     frame.Parent = script.Parent
  30.    
  31.     local ShiftLockIcon = Instance.new('ImageButton')
  32.     ShiftLockIcon.Name = "MouseLockLabel"
  33.     ShiftLockIcon.Size = UDim2.new(1, 0, 1, 0)
  34.     ShiftLockIcon.Position = UDim2.new(0, 0, 0, 0)
  35.     ShiftLockIcon.BackgroundTransparency = 1
  36.     ShiftLockIcon.Image = SHIFT_LOCK_OFF
  37.     ShiftLockIcon.Visible = true
  38.     ShiftLockIcon.Parent = frame
  39.    
  40.     local frame2 = Instance.new('Frame')
  41.     frame2.Name = "MiddleIcon"
  42.     frame2.Size = UDim2.new(.075, 0, .075, 0)
  43.     frame2.Position = UDim2.new(.5, 0, .5, 0)
  44.     frame2.AnchorPoint = Vector2.new(.5,.5)
  45.     frame2.BackgroundTransparency = 1
  46.     frame2.ZIndex = 10
  47.     frame2.Visible = true
  48.     frame2.Parent = script.Parent
  49.    
  50.     local MouseLockCursor = Instance.new('ImageLabel')
  51.     MouseLockCursor.Name = "MouseLockLabel"
  52.     MouseLockCursor.Size = UDim2.new(1, 0, 1, 0)
  53.     MouseLockCursor.Position = UDim2.new(0, 0, 0, 0)
  54.     MouseLockCursor.BackgroundTransparency = 1
  55.     MouseLockCursor.Image = SHIFT_LOCK_CURSOR
  56.     MouseLockCursor.Visible = false
  57.     MouseLockCursor.Parent = frame2
  58.    
  59.     local arc = Instance.new("UIAspectRatioConstraint")
  60.     arc.AspectRatio = 1
  61.     arc.DominantAxis = "Height"
  62.     arc.Parent = frame
  63.     arc:Clone().Parent = frame2
  64.    
  65.     --When the icon is pressed, change the icons and change a value that the RenderStepped below uses.
  66.     local Activated = false
  67.     ShiftLockIcon.Activated:connect(function()
  68.         Activated = not Activated
  69.        
  70.         ShiftLockIcon.Image = Activated and SHIFT_LOCK_ON or SHIFT_LOCK_OFF
  71.         MouseLockCursor.Visible = Activated and SHOW_CENTER_CURSOR
  72.     end)
  73.    
  74.     --Will run every frame just after the default camera.
  75.     local function OnStep()
  76.         if Activated then
  77.             local Camera = workspace.CurrentCamera
  78.             if Camera then
  79.                 local Character = Player.Character
  80.                 local Humanoid = Character and Character:FindFirstChild"Humanoid"
  81.                 local RootPart = Character and Character:FindFirstChild"HumanoidRootPart"
  82.                 local Head = Character and Character:FindFirstChild"Head"
  83.                 if Humanoid and Humanoid.Health > 0 and RootPart then
  84.                     --Rotate the player based off the camera.
  85.                     local LookVector = Camera.CFrame.LookVector
  86.                     RootPart.CFrame = CFrame.new(RootPart.Position) * CFrame.Angles(0,math.atan2(-LookVector.X,-LookVector.Z),0)
  87.                 end
  88.                 --Offsets the player if they aren't in first person.
  89.                 if Head and (Head.Position - Camera.CFrame.Position).Magnitude >= 1 then
  90.                     Camera.CFrame = Camera.CFrame * CFrame.new(1.75,0,0)
  91.                 end
  92.             end
  93.         end
  94.     end
  95.     RunService:BindToRenderStep("MobileShiftLock",Enum.RenderPriority.Camera.Value+1,OnStep)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement