How To Make Touch Screen/Mobile Device Screen Shift Lock Button/How to Enable Shift lock while Clicking With Different Buttons

Here is a small tutorial for cross-platform use, for restricting the user the same way as computer users with DevEnableMouseLock and add a camera offset:

In order to utilize this without breaking computer’s own shift lock, (cross-platform use), you need to check if UserInputService.TouchEnabled is true before setting mouse lock. I’d also recommend using .Changed instead of constantly firing the SetIsMouseLocked function, and check DevEnableMouseLock before firing, which is useful for restricting players. Here is an example of how that would look:

script.Parent.Parent.Parent.isShiftlock.Changed:Connect(function(value) -- When "isShiftlock" value changes, fires function with a "value" parameter
	if UserInputService.TouchEnabled and Players.LocalPlayer.DevEnableMouseLock then -- If DevEnablesMouseLock and TouchEnabled, then
		self.activeCameraController:SetIsMouseLocked(value) -- Set Mouse Lock based on value parameter
	end
end)

This can also be used to hide the UI from computer users and only let mobile users utilize it. To do this, simply clone the UI to the PlayerGui if TouchEnabled is true, or destroy the UI if TouchEnabled is false.

If you’re fond of Shiftlock’s camera offset, you can quite easily add that into the script by checking if the value is true and then adding or removing into Humanoid.CameraOffset. Here is the code:

script.Parent.Parent.Parent.isShiftlock.Changed:Connect(function(value) -- When "isShiftlock" value changes, fires function with a "value" parameter
	if UserInputService.TouchEnabled and Players.LocalPlayer.DevEnableMouseLock then -- If DevEnablesMouseLock and TouchEnabled, then
		self.activeCameraController:SetIsMouseLocked(value) -- Set Mouse Lock based on value parameter
		local Humanoid = Players.LocalPlayer.Character:FindFirstChild("Humanoid") -- Variable Humanoid is defined as the player's humanoid.
		Humanoid.CameraOffset = Vector3.new(0,0,0) -- Humanoid.CameraOffset is reset.
		if value then -- If value is true then
			Humanoid.CameraOffset = Vector3.new(1.75,0,0) -- Humanoid.CameraOffset is equal to a new vector3 value of 1.75 studs in X.
		end
	end
end)

This should be the result:

Enjoy! :grin:

4 Likes