#Need help forcing shiftlock

1 messages · Page 1 of 1 (latest)

onyx grail
#

This is the code im using, and it only locks the mouse in the center, and does not force shiftlock like i thought it would, and im pretty much out of ideas on how to actually make it force shift-lock, any help?

local isShiftLocked = true

local function setShiftLock(state)
    isShiftLocked = state
    
    if isShiftLocked then
        UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
        UIS.MouseIconEnabled = false
    else
        UIS.MouseBehavior = Enum.MouseBehavior.Default
        UIS.MouseIconEnabled = true
    end
end

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftAlt then
        setShiftLock(false)
    end
end)

UIS.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftAlt then
        setShiftLock(true)
    end
end)

plr.CharacterAdded:Connect(function()
    task.wait(0.5)
    setShiftLock(true)
end)

setShiftLock(true)

#

(please ping me)

austere steppe
#

You need to change Player camera too

#

@onyx grail

onyx grail
#

can you elaborate?

#

(on how to do that)

#

@austere steppe

austere steppe
#

Oh I was wrong

#

The shiftlock will lock the player in camera direction right?

#

@onyx grail

onyx grail
#

yes

austere steppe
#

Then change the hrp cframe with new cframe who looks in the same direction as the camera

#

Cframe.lookat(hrp.Position,workspace.currentCamera.lookVector)

#

I think

#

Did it work? @onyx grail

onyx grail
austere steppe
#

@onyx grail

onyx grail
#

im not sure what i would be defining Cframe as

#

wait no

#

its CFrame

austere steppe
#

Wait

#

Show me all the code

onyx grail
#

however, this still gets an error though

austere steppe
#

Show the script

onyx grail
austere steppe
#

You need to do Humanoidrootpart.Cframe = Cframe.lookat(etc)

#

@onyx grail and that will work I think

onyx grail
#

so im confused on

#

what i ened to do then

onyx grail
austere steppe
onyx grail
austere steppe
#

I'm not on pc rn so it's hard to write

#

Wait a sec

onyx grail
#

kk

austere steppe
#

As you already named a variable HumanoidRootPart

#

Do ```lua
Humanoidrootpart.Cframe = Cframe.lookat(Humanoidrootpart.Position, workspace.currentCamera.CFrame.lookVector

#

@onyx grail

onyx grail
#

just like this?

#

now its telling me im trying to call a nil value

austere steppe
#

Show the error

onyx grail
#

this is my first time ever doing camera stuff, so i apologize for being a little confused lol

austere steppe
#

Can you send again the whole script now?

onyx grail
austere steppe
# onyx grail

Can you send the picture with the lines on the 2nd picture pls

onyx grail
austere steppe
#

The lines on the left

onyx grail
#

im not sure hwat you mean so im just sending the entire window

austere steppe
#

Like this

onyx grail
#

columns

#

yes

austere steppe
#

Where is the script?

#

@onyx grail

onyx grail
#

local script inside StarterCharacterScripts

austere steppe
#

Oh the problem is the lookAt function

#

Write like I did

#

lookAt

onyx grail
#

if this is the problem

#

i hate lua

#

😭

#

yeah that was the problem

#

typical lua moment

#

it works pretty fine now

#

i appreciate it man

austere steppe
#

Lol syntax problem are really Boring

austere steppe
#

If you have any questions you can ask

onyx grail
#

oh god

#

the character doesnt stop falling over

#

😭

#

it worked the first time i tried it with the script and now it doesnt work anymore (i didnt change anything)

austere steppe
#

Can you show a video

#

@onyx grail

onyx grail
#

unfortunately no

#

basically the character just flips, spawns facing the floor

#

and then when its toggled on and off it teleports back to the floor

austere steppe
#

Oh I got it

#

Do just before changing the Humanoidrootpart Cframe

local UnitVector = Vector3.new(workspace.currentCamera.CFrame.lookVector.X,0,workspace.currentCamera.CFrame.lookVector.Z)
#

And change the previous changer by this

Humanoidrootpart.Cframe = Cframe.lookat(Humanoidrootpart.Position, UnitVector
#

@onyx grail

onyx grail
#

okay so now its giving me the same

#

nil error value

austere steppe
#

Show the output

onyx grail
#

wait

#

another lua moment

#

okay nope same issue

austere steppe
#

Yeah

onyx grail
#

hmmm

#

wait

#

another lua moment again

#

okay maybe it would be easier to

#

actually get the shiftlock script

#

and just force true it

austere steppe
#

Nah that's not the problem

onyx grail
#

maybe i should

still cargoBOT
#

studio** You are now Level 6! **studio

onyx grail
#

take a break and start this again later

quiet egret
#

when it comes to forcing stuff with the player's cursor there isn't much you can do as it's made like that for the autonomy of the user, the closest you could get using scripts to shiftlock is LockCenter mouse behavior, if your game is something that needs shift lock to be played correctly, I'm sure a player would eventually just use shift lock by themselves.