local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local root = hum.RootPart
local Tool = script.Parent
function shiftLock(active)
if active then
hum.CameraOffset = Vector3.new(1.75,0,0)
hum.AutoRotate = false
RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0,y,0)
end)
else
hum.CameraOffset = Vector3.new(0,0,0)
RunService:UnbindFromRenderStep("ShiftLock")
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
hum.AutoRotate = true
end
end
Tool.Equipped:Connect(function()
shiftLock(true)
end)
Tool.Unequipped:Connect(function()
shiftLock(false)
end)
It works perfectly in the test place of my game, but when i add the tool into my main game place, it still changes the MouseBehaviour when equipping and unequipping the tool, but doesn’t do anything else.
I know it’s not interacting with any other scripts, because i tried downloading a copy of my main place and i deleted every script in starterplayer and serverscriptservice, and it was doing the exact same thing.
I’m not too experienced in scripting, but i have moderate knowledge and i seriously have no clue what could be causing this.
It works fine in newly created places, if i create a brand new place and put the tool in it works just fine, but in the main game place i’m working on, which was created 1 or 2 years ago, for some reason causes it to stop working.
When I open a large file that requires time to load, the script doesn’t function properly. Therefore, instead of using “local char = plr.Character”, I use “local char = plr.Character or plr.CharacterAdded:Wait()”. The file is created in 2018 and it is functioning when character loaded.
Since there is lack of information about your game place, I can’t solve your problem .But if you want a Shift-Lock when holding weapon you can follow like this.
First, copy entire PlayerModule. Then create a Bindable event called “ShiftLock_Event”
Change the line 123 code in CameraModule where under PlayerModule
if not UserInputService.TouchEnabled then --- line 123
self.activeMouseLockController = MouseLockController.new()
local toggleEvent = self.activeMouseLockController:GetBindableToggleEvent()
if toggleEvent then
toggleEvent:Connect(function()
self:OnMouseLockToggled()
end)
end
local ShiftLock_Event = script.Parent.ShiftLock_Event
if ShiftLock_Event then
ShiftLock_Event.Event:Connect(function(input)
self:OnMouseLockToggled(input)
end)
end
end
Finding “OnMouseLockToggled” In CameraModule and change the script like this
function CameraModule:OnMouseLockToggled(input) --- 560~570
if self.activeMouseLockController then
local mouseLockOffset = self.activeMouseLockController:GetMouseLockOffset()
local mouseLocked = self.activeMouseLockController:GetIsMouseLocked()
if input ~= nil then
if self.activeCameraController then
self.activeCameraController:SetIsMouseLocked(input)
self.activeCameraController:SetMouseLockOffset(mouseLockOffset)
end
else
if self.activeCameraController then
self.activeCameraController:SetIsMouseLocked(mouseLocked)
self.activeCameraController:SetMouseLockOffset(mouseLockOffset)
end
end
end
end
Create Local Script under tool and copy this script
local Tool = script.Parent
local PlayerMoudle = game.Players.LocalPlayer.PlayerScripts.PlayerModule
local CameraModule =require(PlayerMoudle.CameraModule)
local MouseLockController = require(PlayerMoudle.CameraModule.MouseLockController)
ShiftLock_Event = PlayerMoudle.ShiftLock_Event
function shiftLock(Active)
ShiftLock_Event:Fire(Active)
end
Tool.Equipped:Connect(function()
shiftLock(true)
end)
Tool.Unequipped:Connect(function()
shiftLock(false)
end)