How to shift lock mobile

Hello, so i have this script that sets the players mouse to the center of the screen(works perfectly, plz dont try to change anything meaningful in this script), but i want this to also work on mobile, where the mouse is visible and stuff and the players “touch signal” are there.

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local UserInputService = game:GetService("UserInputService")
local root = hum.RootPart -- The HumanoidRootPart
---------------------------------------------------------
local RunService = game:GetService("RunService")
--Toggle Function:
function shiftLock(active) --Toggle shift.lock function
	if active then		
		hum.CameraOffset = Vector3.new(0,1.75,0) -- I assume this is about the right camera offset.
		

		RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --Set the mouse to center every frame.

			local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ() --Get the angles of the camera
			
		end) 
	else
		
		hum.CameraOffset = Vector3.new(0,0,0) --Move the camera back to normal.
		RunService:UnbindFromRenderStep("ShiftLock") -- Allow mouse to move freely.
		UserInputService.MouseBehavior = Enum.MouseBehavior.Default -- Let the mouse move freely
	end
end
--Disable and Enable:
shiftLock(true) -- Toggle shift lock
print("Shift lock turned on!")
1 Like
1 Like