Is this ShiftLock script well done for mobile devices?

Hello, lately in my game people ask me to put the shiflock for cell phones, the truth was that I had no idea how to do it, so I decided to get a free model, but I’m afraid that their scripts have some kind of virus, so I wanted to know If you could tell me if the following scripts are safe and well done, if not, please tell me how to do it. Thank you

Shiftlock script:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local Settings = UserSettings()
local GameSettings = Settings.GameSettings
local ShiftLockController = {}
while not Players.LocalPlayer do
	wait()
end
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local ScreenGui, ShiftLockIcon, InputCn
local IsShiftLockMode = true
local IsShiftLocked = true
local IsActionBound = false
local IsInFirstPerson = false
ShiftLockController.OnShiftLockToggled = Instance.new("BindableEvent")
local function isShiftLockMode()
	return LocalPlayer.DevEnableMouseLock and GameSettings.ControlMode == Enum.ControlMode.MouseLockSwitch and LocalPlayer.DevComputerMovementMode ~= Enum.DevComputerMovementMode.ClickToMove and GameSettings.ComputerMovementMode ~= Enum.ComputerMovementMode.ClickToMove and LocalPlayer.DevComputerMovementMode ~= Enum.DevComputerMovementMode.Scriptable
end
if not UserInputService.TouchEnabled then
	IsShiftLockMode = isShiftLockMode()
end
local function onShiftLockToggled()
	IsShiftLocked = not IsShiftLocked
	ShiftLockController.OnShiftLockToggled:Fire()
end
local initialize = function()
	print("enabled")
end
function ShiftLockController:IsShiftLocked()
	return IsShiftLockMode and IsShiftLocked
end
function ShiftLockController:SetIsInFirstPerson(isInFirstPerson)
	IsInFirstPerson = isInFirstPerson
end
local function mouseLockSwitchFunc(actionName, inputState, inputObject)
	if IsShiftLockMode then
		onShiftLockToggled()
	end
end
local function disableShiftLock()
	if ScreenGui then
		ScreenGui.Parent = nil
	end
	IsShiftLockMode = false
	Mouse.Icon = ""
	if InputCn then
		InputCn:disconnect()
		InputCn = nil
	end
	IsActionBound = false
	ShiftLockController.OnShiftLockToggled:Fire()
end
local onShiftInputBegan = function(inputObject, isProcessed)
	if isProcessed then
		return
	end
	if inputObject.UserInputType ~= Enum.UserInputType.Keyboard or inputObject.KeyCode == Enum.KeyCode.LeftShift or inputObject.KeyCode == Enum.KeyCode.RightShift then
	end
end
local function enableShiftLock()
	IsShiftLockMode = isShiftLockMode()
	if IsShiftLockMode then
		if ScreenGui then
			ScreenGui.Parent = PlayerGui
		end
		if IsShiftLocked then
			ShiftLockController.OnShiftLockToggled:Fire()
		end
		if not IsActionBound then
			InputCn = UserInputService.InputBegan:connect(onShiftInputBegan)
			IsActionBound = true
		end
	end
end
GameSettings.Changed:connect(function(property)
	if property == "ControlMode" then
		if GameSettings.ControlMode == Enum.ControlMode.MouseLockSwitch then
			enableShiftLock()
		else
			disableShiftLock()
		end
	elseif property == "ComputerMovementMode" then
		if GameSettings.ComputerMovementMode == Enum.ComputerMovementMode.ClickToMove then
			disableShiftLock()
		else
			enableShiftLock()
		end
	end
end)
LocalPlayer.Changed:connect(function(property)
	if property == "DevEnableMouseLock" then
		if LocalPlayer.DevEnableMouseLock then
			enableShiftLock()
		else
			disableShiftLock()
		end
	elseif property == "DevComputerMovementMode" then
		if LocalPlayer.DevComputerMovementMode == Enum.DevComputerMovementMode.ClickToMove or LocalPlayer.DevComputerMovementMode == Enum.DevComputerMovementMode.Scriptable then
			disableShiftLock()
		else
			enableShiftLock()
		end
	end
end)
LocalPlayer.CharacterAdded:connect(function(character)
	if not UserInputService.TouchEnabled then
		initialize()
	end
end)
if not UserInputService.TouchEnabled then
	initialize()
	if isShiftLockMode() then
		InputCn = UserInputService.InputBegan:connect(onShiftInputBegan)
		IsActionBound = true
	end
end
enableShiftLock()
return ShiftLockController

GUI shiftlock:

local MobileCameraFramework = {}

local players = game:GetService("Players")

local runservice = game:GetService("RunService")

local CAS = game:GetService("ContextActionService")

local player = players.LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()

local root = character:WaitForChild("HumanoidRootPart")

local humanoid = character.Humanoid

local camera = workspace.CurrentCamera

local button = script.Parent

uis = game:GetService("UserInputService")

ismobile = uis.TouchEnabled

button.Visible = ismobile --Mobile only--

local states = {

OFF = "rbxasset://textures/ui/mouseLock_off@2x.png",

ON = "rbxasset://textures/ui/mouseLock_on@2x.png"

}

local MAX_LENGTH = 900000

local active = false

local ENABLED_OFFSET = CFrame.new(1.7, 0, 0)

local DISABLED_OFFSET = CFrame.new(-1.7, 0, 0)

local function UpdateImage(STATE)

button.Image = states[STATE]

end

local function UpdateAutoRotate(BOOL)

humanoid.AutoRotate = BOOL

end

local function GetUpdatedCameraCFrame(ROOT, CAMERA)

return CFrame.new(root.Position, Vector3.new(CAMERA.CFrame.LookVector.X * MAX_LENGTH, root.Position.Y, CAMERA.CFrame.LookVector.Z * MAX_LENGTH))

end

local function EnableShiftlock()

UpdateAutoRotate(false)

UpdateImage("ON")

root.CFrame = GetUpdatedCameraCFrame(root, camera)

camera.CFrame = camera.CFrame * ENABLED_OFFSET

end

local function DisableShiftlock()

UpdateAutoRotate(true)

UpdateImage("OFF")

camera.CFrame = camera.CFrame * DISABLED_OFFSET

pcall(function()

active:Disconnect()

active = nil

end)

end

UpdateImage("OFF")

active = false

function ShiftLock()

if not active then

active = runservice.RenderStepped:Connect(function()

EnableShiftlock()

end)

else

DisableShiftlock()

end

end

local ShiftLockButton = CAS:BindAction("ShiftLOCK", ShiftLock, false, "On")

CAS:SetPosition("ShiftLOCK", UDim2.new(0.8, 0, 0.8, 0))

button.MouseButton1Click:Connect(function()

if not active then

active = runservice.RenderStepped:Connect(function()

EnableShiftlock()

end)

else

DisableShiftlock()

end

end)

return MobileCameraFramework

Something that seems strange to me is that at the end of the scripts there is a lot of white space and it cannot be deleted

This category is only to ask help for a code that youself wrote. If you dont wrote it, you cant place it here. Then, if you are affraid that it contains a virus, you could test it on another game with a blank baseplate and search any suspicious activity while running the code. And, you dont have to exactly ask someone to controll the code: If you search a bit, you will find out how the most „virus“ codes works (like, they use getfenv and setfenv functions, or require a script with the require(ID) function).

The best solution would to do it youself. You always can look into toolbox scripts, but you aren’t always secure that it’s safe. Search for tutorials on youtube, snd for your case search to understand how it works. If you understand how it works it will help you a lot to create your own code from nothing

Shiftlock works with camera, so start understanding how to modify the camera (like it’s position), then start learn keybinding (ContextActionService) and combine the whole.

Some links:

I don’t understand why you dont want to use Roblox default Shiftlock, I thought it would works for mobile, correct me if I am wrong.

1 Like

Don’t worry about this - there is a new setting in Studio to be able to scroll past the end of the script a bit to bring the last line further up the screen. You can switch it off in Studio settings.

image

So long as that whitespace doesn’t have line numbers - there isn’t actually whitespace there. You can also check the setting “Show Whitespace” which puts symbols in for tabs and spaces to help check your whitespace is consistent and there isn’t any unnecessary spaces/tabs.

1 Like

This system seems pretty clean. Good luck on your game!