I need some support for my shift-lock script modification.
The smooth shift-lock which I found online works perfectly, it’s just that I modified it for mobile support. It works, it’s just that the icon of the shift-lock is just the default mouse, and not the set cursor.
Previously I used the old method of changing the icon, which of course didn’t work. But, I tried using the new method (UserInputService.MouseIcon), which didn’t work either.
Current script:
local SmoothShiftLock = {}
SmoothShiftLock.__index = SmoothShiftLock
local Players = game:GetService("Players")
local WorkspaceService = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Maid = require(script.Utils:WaitForChild("Maid"))
local Spring = require(script.Utils:WaitForChild("Spring"))
local LocalPlayer = Players.LocalPlayer
local Remotes = ReplicatedStorage:WaitForChild("Assets"):WaitForChild("Remotes")
local remShiftlock = Remotes:WaitForChild("Shiftlock")
local config = {
CHARACTER_SMOOTH_ROTATION = true,
CHARACTER_ROTATION_SPEED = 3,
TRANSITION_SPRING_DAMPER = 0.7,
CAMERA_TRANSITION_IN_SPEED = 10,
CAMERA_TRANSITION_OUT_SPEED = 14,
LOCKED_CAMERA_OFFSET = Vector3.new(1.75, 0.25, 0),
LOCKED_MOUSE_ICON = "rbxasset://137871496184596",
SHIFT_LOCK_KEYBINDS = {Enum.KeyCode.LeftControl, Enum.KeyCode.RightControl}
}
local maid = Maid.new()
function SmoothShiftLock:Init()
local managerMaid = Maid.new()
managerMaid:GiveTask(LocalPlayer.CharacterAdded:Connect(function()
self:CharacterAdded()
end))
if LocalPlayer.Character then
self:CharacterAdded()
end
end
function SmoothShiftLock:CharacterAdded()
local self = setmetatable({}, SmoothShiftLock)
self.Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
self.RootPart = self.Character:WaitForChild("HumanoidRootPart")
self.Humanoid = self.Character:WaitForChild("Humanoid")
self.Head = self.Character:WaitForChild("Head")
self.PlayerMouse = LocalPlayer:GetMouse()
self.Camera = WorkspaceService.CurrentCamera
self.ENABLED = false
self.connectionsMaid = Maid.new()
self.camOffsetSpring = Spring.new(Vector3.new(0, 0, 0))
self.camOffsetSpring.Damper = config.TRANSITION_SPRING_DAMPER
self.connectionsMaid:GiveTask(UserInputService.InputBegan:Connect(function(input, gpe)
if table.find(config.SHIFT_LOCK_KEYBINDS, input.KeyCode) and self.Humanoid and self.Humanoid.Health > 0 then
self:ToggleShiftLock(not self.ENABLED)
end
end))
self.connectionsMaid:GiveTask(RunService.RenderStepped:Connect(function()
if self.Head.LocalTransparencyModifier > 0.6 then return end;
local camCF = self.Camera.CFrame
local distance = (self.Head.Position - camCF.p).Magnitude
if distance > 1 then
self.Camera.CFrame = self.Camera.CFrame * CFrame.new(self.camOffsetSpring.Position)
if self.ENABLED then
if UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
self:SetMouseState(true)
end
UserInputService.MouseIcon = config.LOCKED_MOUSE_ICON
else
UserInputService.MouseIcon = ""
end
end
end))
self.connectionsMaid:GiveTask(remShiftlock.OnClientEvent:Connect(function(action)
if action == "toggle" then
self:ToggleShiftLock(not self.ENABLED)
elseif action == "enable" then
self:ToggleShiftLock(true)
elseif action == "disable" then
self:ToggleShiftLock(false)
end
end))
self.connectionsMaid:GiveTask(self.Humanoid.Died:Connect(function()
self:CharacterDiedOrRemoved()
end))
self.connectionsMaid:GiveTask(LocalPlayer.CharacterRemoving:Connect(function()
self:CharacterDiedOrRemoved()
end))
return self
end
function SmoothShiftLock:CharacterDiedOrRemoved()
self:ToggleShiftLock(false)
if self.connectionsMaid then
self.connectionsMaid:Destroy()
end
maid:DoCleaning()
end
function SmoothShiftLock:IsEnabled()
return self.ENABLED
end
function SmoothShiftLock:SetMouseState(enable)
UserInputService.MouseBehavior = enable and Enum.MouseBehavior.LockCenter or Enum.MouseBehavior.Default
end
function SmoothShiftLock:SetMouseIcon(enable : boolean)
if enable then
UserInputService.MouseIcon = config.LOCKED_MOUSE_ICON
else
UserInputService.MouseIcon = ""
end
end
function SmoothShiftLock:TransitionLockOffset(enable)
if enable then
self.camOffsetSpring.Speed = config.CAMERA_TRANSITION_IN_SPEED
self.camOffsetSpring.Target = config.LOCKED_CAMERA_OFFSET
else
self.camOffsetSpring.Speed = config.CAMERA_TRANSITION_OUT_SPEED
self.camOffsetSpring.Target = Vector3.new(0, 0, 0)
end
end
function SmoothShiftLock:ToggleShiftLock(enable)
assert(typeof(enable) == "boolean")
self.ENABLED = enable
self:SetMouseState(self.ENABLED)
self:SetMouseIcon(self.ENABLED)
self:TransitionLockOffset(self.ENABLED)
if self.ENABLED then
maid:GiveTask(RunService.RenderStepped:Connect(function(delta)
if self.Humanoid and self.RootPart then
self.Humanoid.AutoRotate = not self.ENABLED
end
if self.ENABLED then
if not self.Humanoid.Sit and config.CHARACTER_SMOOTH_ROTATION then
local _, y, _ = self.Camera.CFrame:ToOrientation()
self.RootPart.CFrame = self.RootPart.CFrame:Lerp(
CFrame.new(self.RootPart.Position) * CFrame.Angles(0, y, 0),
delta * 5 * config.CHARACTER_ROTATION_SPEED
)
elseif not self.Humanoid.Sit then
local _, y, _ = self.Camera.CFrame:ToOrientation()
self.RootPart.CFrame = CFrame.new(self.RootPart.Position) * CFrame.Angles(0, y, 0)
end
else
maid:Destroy()
end
end))
end
return self
end
return SmoothShiftLock