I’m just wondering if there’s a way to code shiftlock for people who use Xbox/Playstation. I have looked everywhere and can’t find a solution.
I’m not a pro scripter but I think you can use this method
first, copy this from the player when are playing the game
and second edit this script
and just choose one of the controller’s buttons for the shift lock key
and don’t forget to set them in here too
or you can write some kind of code that when you for example press Y on the controller lock the player head and the camera at the mouse position
as I said I’m new at scripting I just wanted to help you and I hope I gave you something that helps you!
Edit:
here is the shift lock script for reference
--!nonstrict
--[[
MouseLockController - Replacement for ShiftLockController, manages use of mouse-locked mode
2018 Camera Update - AllYourBlox
--]]
--[[ Constants ]]--
local DEFAULT_MOUSE_LOCK_CURSOR = "rbxassetid://14913864161"
local CONTEXT_ACTION_NAME = "MouseLockSwitchAction"
local MOUSELOCK_ACTION_PRIORITY = Enum.ContextActionPriority.Medium.Value
--[[ Services ]]--
local PlayersService = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local Settings = UserSettings() -- ignore warning
local GameSettings = Settings.GameSettings
--[[ Imports ]]
local CameraUtils = require(script.Parent:WaitForChild("CameraUtils"))
--[[ The Module ]]--
local MouseLockController = {}
MouseLockController.__index = MouseLockController
function MouseLockController.new()
local self = setmetatable({}, MouseLockController)
self.isMouseLocked = false
self.savedMouseCursor = nil
self.boundKeys = {Enum.KeyCode.LeftAlt, Enum.KeyCode.RightAlt} -- defaults
self.mouseLockToggledEvent = Instance.new("BindableEvent")
local boundKeysObj = script:FindFirstChild("BoundKeys")
if (not boundKeysObj) or (not boundKeysObj:IsA("StringValue")) then
-- If object with correct name was found, but it's not a StringValue, destroy and replace
if boundKeysObj then
boundKeysObj:Destroy()
end
boundKeysObj = Instance.new("StringValue")
-- Luau FIXME: should be able to infer from assignment above that boundKeysObj is not nil
assert(boundKeysObj, "")
boundKeysObj.Name = "BoundKeys"
boundKeysObj.Value = "LeftAlt,RightAlt"
boundKeysObj.Parent = script
end
if boundKeysObj then
boundKeysObj.Changed:Connect(function(value)
self:OnBoundKeysObjectChanged(value)
end)
self:OnBoundKeysObjectChanged(boundKeysObj.Value) -- Initial setup call
end
-- Watch for changes to user's ControlMode and ComputerMovementMode settings and update the feature availability accordingly
GameSettings.Changed:Connect(function(property)
if property == "ControlMode" or property == "ComputerMovementMode" then
self:UpdateMouseLockAvailability()
end
end)
-- Watch for changes to DevEnableMouseLock and update the feature availability accordingly
PlayersService.LocalPlayer:GetPropertyChangedSignal("DevEnableMouseLock"):Connect(function()
self:UpdateMouseLockAvailability()
end)
-- Watch for changes to DevEnableMouseLock and update the feature availability accordingly
PlayersService.LocalPlayer:GetPropertyChangedSignal("DevComputerMovementMode"):Connect(function()
self:UpdateMouseLockAvailability()
end)
self:UpdateMouseLockAvailability()
return self
end
function MouseLockController:GetIsMouseLocked()
return self.isMouseLocked
end
function MouseLockController:GetBindableToggleEvent()
return self.mouseLockToggledEvent.Event
end
function MouseLockController:GetMouseLockOffset()
local offsetValueObj: Vector3Value = script:FindFirstChild("CameraOffset") :: Vector3Value
if offsetValueObj and offsetValueObj:IsA("Vector3Value") then
return offsetValueObj.Value
else
-- If CameraOffset object was found but not correct type, destroy
if offsetValueObj then
offsetValueObj:Destroy()
end
offsetValueObj = Instance.new("Vector3Value")
assert(offsetValueObj, "")
offsetValueObj.Name = "CameraOffset"
offsetValueObj.Value = Vector3.new(2.25,0.5,0) -- Legacy Default Value
offsetValueObj.Parent = script
end
if offsetValueObj and offsetValueObj.Value then
return offsetValueObj.Value
end
return Vector3.new(1.75,0,0)
end
function MouseLockController:UpdateMouseLockAvailability()
local devAllowsMouseLock = PlayersService.LocalPlayer.DevEnableMouseLock
local devMovementModeIsScriptable = PlayersService.LocalPlayer.DevComputerMovementMode == Enum.DevComputerMovementMode.Scriptable
local userHasMouseLockModeEnabled = GameSettings.ControlMode == Enum.ControlMode.MouseLockSwitch
local userHasClickToMoveEnabled = GameSettings.ComputerMovementMode == Enum.ComputerMovementMode.ClickToMove
local MouseLockAvailable = devAllowsMouseLock and userHasMouseLockModeEnabled and not userHasClickToMoveEnabled and not devMovementModeIsScriptable
if MouseLockAvailable~=self.enabled then
self:EnableMouseLock(MouseLockAvailable)
end
end
function MouseLockController:OnBoundKeysObjectChanged(newValue: string)
self.boundKeys = {} -- Overriding defaults, note: possibly with nothing at all if boundKeysObj.Value is "" or contains invalid values
for token in string.gmatch(newValue,"[^%s,]+") do
for _, keyEnum in pairs(Enum.KeyCode:GetEnumItems()) do
if token == keyEnum.Name then
self.boundKeys[#self.boundKeys+1] = keyEnum :: Enum.KeyCode
break
end
end
end
self:UnbindContextActions()
self:BindContextActions()
end
--[[ Local Functions ]]--
function MouseLockController:OnMouseLockToggled()
self.isMouseLocked = not self.isMouseLocked
if self.isMouseLocked then
local cursorImageValueObj: StringValue? = script:FindFirstChild("CursorImage") :: StringValue?
if cursorImageValueObj and cursorImageValueObj:IsA("StringValue") and cursorImageValueObj.Value then
CameraUtils.setMouseIconOverride(cursorImageValueObj.Value)
else
if cursorImageValueObj then
cursorImageValueObj:Destroy()
end
cursorImageValueObj = Instance.new("StringValue")
assert(cursorImageValueObj, "")
cursorImageValueObj.Name = "CursorImage"
cursorImageValueObj.Value = DEFAULT_MOUSE_LOCK_CURSOR
cursorImageValueObj.Parent = script
CameraUtils.setMouseIconOverride(DEFAULT_MOUSE_LOCK_CURSOR)
end
else
CameraUtils.restoreMouseIcon()
end
self.mouseLockToggledEvent:Fire()
end
function MouseLockController:DoMouseLockSwitch(name, state, input)
if state == Enum.UserInputState.Begin then
self:OnMouseLockToggled()
return Enum.ContextActionResult.Sink
end
return Enum.ContextActionResult.Pass
end
function MouseLockController:BindContextActions()
ContextActionService:BindActionAtPriority(CONTEXT_ACTION_NAME, function(name, state, input)
return self:DoMouseLockSwitch(name, state, input)
end, false, MOUSELOCK_ACTION_PRIORITY, unpack(self.boundKeys))
end
function MouseLockController:UnbindContextActions()
ContextActionService:UnbindAction(CONTEXT_ACTION_NAME)
end
function MouseLockController:IsMouseLocked(): boolean
return self.enabled and self.isMouseLocked
end
function MouseLockController:EnableMouseLock(enable: boolean)
if enable ~= self.enabled then
self.enabled = enable
if self.enabled then
-- Enabling the mode
self:BindContextActions()
else
-- Disabling
-- Restore mouse cursor
CameraUtils.restoreMouseIcon()
self:UnbindContextActions()
-- If the mode is disabled while being used, fire the event to toggle it off
if self.isMouseLocked then
self.mouseLockToggledEvent:Fire()
end
self.isMouseLocked = false
end
end
end
return MouseLockController
Something like this?
So when the player presses Y they should toggle shiftlock.
Edit: Im gonna go test this on my xbox rq
found something
As shown by Zolp in their YouTube video, Shift Lock on an Xbox can be activated by repeatedly pressing the “RT” trigger button on the controller until the white crosshair shows on the screen, which might take up to six presses. As soon as that happens, you can turn Shift Lock on and off with a single push of the same button.
and about that ButtonY i didn’t ever script for xbox/playstation but if it’s called ButtonY you have to change the shift lock button in the script to ButtonY too.
as i said im new in scripting but ill keep searching for you
The playerMoudle script didnt work. And yes I am using the right key name for ButtonY. For that shift lock script where would i put it?
about the shiftlock script i mean MouseLockController in that i showed in that image
you have to change this line
self.boundKeys = {Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift
(note:mine is RightAlt,LeftAlt)
to
self.boundKeys = {Enum.KeyCode.ButtonY
and dont forget to put the player module in the correct folder (starterplayerscripts)
and dont forget to save the changes
Alright I changed it. I’m gonna go test it again and hopefully it works.
Again, nothing. I have saved and published the game, the player module is in starterplayerscripts and i have updated the code too.
self.boundKeys = {Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift, Enum.KeyCode.ButtonY}
I have seen other games accomplish this, such as BEAR. I’m not so sure how they might have done it tho.
i found something that may help you:
Thanks! Will look into this soon.