LeftAlt Shift-lock doesn't work in game until i reset character

Problem is in the title, work’s perfectly fine in studio but not in the actual game.
~
You can see for yourself here: A Night to Dread Testing Centre P0.0.1 - Roblox

Feedback is greatly appreciated!

Could you give some more info? Code snippets or something?

Oh yeah sorry about that I forgot to include that, I use @Rixtys99’s SmoothShiftLock module, which is seen below:

Local Script
local SmoothShiftLock = {}
SmoothShiftLock.__index = SmoothShiftLock;

-- [[ Variables ]]:

--// Services and requires
local Players = game:GetService("Players");
local WorkspaceService = game:GetService("Workspace");
local RunService = game:GetService("RunService");
local UserInputService = game:GetService("UserInputService");
local TweenService = game:GetService("TweenService");
local Maid = require(script.Utils:WaitForChild("Maid"));
local Spring = require(script.Utils:WaitForChild("Spring"));

--// Instances
local LocalPlayer = Players.LocalPlayer;

--// Bindables
local ToggleEvent = script:WaitForChild("ToggleShiftLock");

--// Configuration
local config = {
	["CHARACTER_SMOOTH_ROTATION"]   = true,                       --// If your character should rotate smoothly or not
	["CHARACTER_ROTATION_SPEED"]    = 3,                          --// How quickly character rotates smoothly
	["TRANSITION_SPRING_DAMPER"]    = 0.7,                        --// Camera transition spring damper, test it out to see what works for you
	["CAMERA_TRANSITION_IN_SPEED"]  = 10,                         --// How quickly locked camera moves to offset position
	["CAMERA_TRANSITION_OUT_SPEED"] = 14,                         --// How quickly locked camera moves back from offset position
	["LOCKED_CAMERA_OFFSET"]        = Vector3.new(1.75, 0.25, -7), --// Locked camera offset
	["LOCKED_MOUSE_ICON"]           =                             --// Locked mouse icon
		"rbxassetid://113689990122252",
	["SHIFT_LOCK_KEYBINDS"]         =                             --// Shift lock keybinds
		{Enum.KeyCode.LeftAlt}
}

--// Setup
local maid = Maid.new();

-- [[ Functions ]]:

--// Setup smooth shift lock on client (Run once and on a LocalScript)
function SmoothShiftLock:Init()
	local managerMaid = Maid.new();

	managerMaid:GiveTask(LocalPlayer.CharacterAdded:Connect(function()
		self:CharacterAdded();
	end));
end;

--// Character added event function
function SmoothShiftLock:CharacterAdded()
	local self = setmetatable({}, SmoothShiftLock);
	--// Instances
	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");
	--// Other
	self.PlayerMouse = LocalPlayer:GetMouse();
	self.Camera = WorkspaceService.CurrentCamera;
	--// Setup
	self.ENABLED = false;
	self.connectionsMaid = Maid.new();
	self.camOffsetSpring = Spring.new(Vector3.new(0, 0, 0));
	self.camOffsetSpring.Damper = config.TRANSITION_SPRING_DAMPER;
	
	--// Bind keybinds
	self.connectionsMaid:GiveTask(UserInputService.InputBegan:Connect(function(input, gpe)
		if (gpe) then return end;

		for _, keyBind in pairs(config.SHIFT_LOCK_KEYBINDS) do
			if (input.KeyCode == keyBind) and (self.Humanoid and self.Humanoid.Health ~= 0) then
				self:ToggleShiftLock(not self.ENABLED);
			end;
		end;
	end));

	--// Update camera offset
	self.connectionsMaid:GiveTask(RunService.RenderStepped:Connect(function()
		if self.Head.LocalTransparencyModifier > 0.6 then return end;
		
		local camCF = self.Camera.CoordinateFrame;
		local distance = (self.Head.Position - camCF.p).magnitude;

		--// Camera offset
		if (distance > 1) then	
			self.Camera.CFrame = (self.Camera.CFrame * CFrame.new(self.camOffsetSpring.Position)); 
			
			if (self.ENABLED) and (UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter) then
				self:SetMouseState(self.ENABLED);
			end;
		end;
	end));
	
	--// Bindables
	self.connectionsMaid:GiveTask(ToggleEvent.Event:Connect(function(toggle: boolean)
		if (self.Humanoid and self.Humanoid.Health ~= 0) then
			self:ToggleShiftLock(toggle);
		end;
	end));
	
	--// On death
	self.connectionsMaid:GiveTask(self.Humanoid.Died:Connect(function()
		self:CharacterDiedOrRemoved();
		return;
	end));
	
	--// On character removing
	self.connectionsMaid:GiveTask(LocalPlayer.CharacterRemoving:Connect(function()
		self:CharacterDiedOrRemoved();
		return;
	end));

	return self;
end;

--// Stop shiftlock upon character death or removal
function SmoothShiftLock:CharacterDiedOrRemoved()
	self:ToggleShiftLock(false);
	
	if self.connectionsMaid ~= nil then
		self.connectionsMaid:Destroy();
	end;
	
	maid:DoCleaning();
end;

--// Return shiftlock enabled state
function SmoothShiftLock:IsEnabled(): boolean
	return self.ENABLED;
end;

--// Set Enum.MouseBehavior to LockCenter or Default depending on shiftlock enabled
function SmoothShiftLock:SetMouseState(enable : boolean)
	UserInputService.MouseBehavior = (enable and Enum.MouseBehavior.LockCenter) or (Enum.MouseBehavior.Default);
end;

--// Change mouse icon depending on shiftlock enabled
function SmoothShiftLock:SetMouseIcon(enable : boolean)
	self.PlayerMouse.Icon = (enable and config.LOCKED_MOUSE_ICON :: string) or "rbxassetid://113689990122252";
end;

--// Tween locked camera offset position
function SmoothShiftLock:TransitionLockOffset(enable : boolean)
	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;

--// Toggle shift lock
function SmoothShiftLock:ToggleShiftLock(enable : boolean)
	assert(typeof(enable) == typeof(false), "Enable value is not a boolean.");
	self.ENABLED = enable;

	self:SetMouseState(self.ENABLED);
	self:SetMouseIcon(self.ENABLED);
	self:TransitionLockOffset(self.ENABLED);
	
	--// Start
	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;
			
			--// Rotate character
			if (self.ENABLED) then
				if not (self.Humanoid.Sit) and (config.CHARACTER_SMOOTH_ROTATION) then
					local x, y, z = 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 x, y, z = self.Camera.CFrame:ToOrientation();
					self.RootPart.CFrame = CFrame.new(self.RootPart.Position) * CFrame.Angles(0, y, 0);
				end;
			end;
			
			--// Stop
			if not (self.ENABLED) then 
				maid:Destroy() end;
		end));
	end;
	
	return self;
end;

return SmoothShiftLock;

You’re using an old version of the script, in newer versions this should be already fixed.

If you want to make work in your current version (I’d recommend updatinting) then replacing:

function SmoothShiftLock:Init()
	local managerMaid = Maid.new();

	managerMaid:GiveTask(LocalPlayer.CharacterAdded:Connect(function()
		self:CharacterAdded();
	end));
end;

, with:

function SmoothShiftLock:Init()
	local managerMaid = Maid.new();

    if LocalPlayer.Character then
		self:CharacterAdded();
    end;

	managerMaid:GiveTask(LocalPlayer.CharacterAdded:Connect(function()
		self:CharacterAdded();
	end));
end;

should fix it.

1 Like

I ended up installing the new one, works perfectly, thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.