Recently, I made a system that detected input changes as well as allowed mobile shift lock. I’d just like to know if there is any way I could improve on what I have.
Changes the input type, in a LocalScript in StarterGui
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local inputVal = plr:WaitForChild("InputType")
if UIS.TouchEnabled then
script.Parent.Parent.Enabled = true
inputVal.Value = "Mobile"
else
script.Parent.Parent.Enabled = false
if UIS.GamepadEnabled then
inputVal.Value = "Controller"
end
end
UIS.LastInputTypeChanged:Connect(function(prevType)
local controller = false
if prevType == Enum.UserInputType.Touch then
script.Parent.Parent.Enabled = true
inputVal.Value = "Mobile"
else
script.Parent.Parent.Enabled = false
plr.isShiftlock.Value = false
for i = 1, 8, 1 do
if prevType == Enum.UserInputType["Gamepad"..i] then
controller = true
inputVal.Value = "Controller"
end
end
end
if not controller and prevType ~= Enum.UserInputType.Touch then
inputVal.Value = "KBM"
end
end)
local colors = {Color3.fromRGB(255,255,255), Color3.fromRGB(26, 255, 248)}
script.Parent.MouseButton1Click:Connect(function()
plr.isShiftlock.Value = not plr.isShiftlock.Value
if script.Parent.ImageColor3 == colors[1] then
script.Parent.ImageColor3 = colors[2]
else
script.Parent.ImageColor3 = colors[1]
end
end)
Changes whether or not a mobile player is shift-locked, inside of CameraModule:Update()
if UserInputService.TouchEnabled then
local isShiftlock = game.Players.LocalPlayer:FindFirstChild("isShiftlock")
if isShiftlock then
self.activeCameraController:SetIsMouseLocked(isShiftlock.Value)
end
end
Script that adds values to players
local function plrJoined(plr)
local isShiftLock = Instance.new("BoolValue")
isShiftLock.Name = "isShiftlock"
isShiftLock.Parent = plr
local inputType = Instance.new("StringValue")
inputType.Name = "InputType"
inputType.Parent = plr
end
game.Players.PlayerAdded:Connect(plrJoined)
Thanks in advance!