UserInputService.MouseBehaviour not working?

Hello!

So I was working on an FPS script, and I tried centering the mouse using this line of code:

UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

Nothing in the output, and no mouse being centered.

Thanks!

3 Likes

Where is it placed in the DataModel, and in what type of script?

StarterPlayerScripts, and LocalScript. :slight_smile:

Is there any code before it that could be causing it to yield?

Nope. The rest of the script is also executed. It’s acting as if that line of code doesn’t exist.

Is it possible that the following applies to your use case?

Nope, there’s no UI. It’s so weird.

Try setting the sensitivity to 0.

UserInputService.MouseDeltaSensitivity = 0

I tried that, and I printed both the MouseBehaviour and the MouseDeltaSensitivity. It printed what it was supposed to. I am very, very confused.

Can you show me the exact behavior of the mouse after setting it?

Here you go.

Hm. Not really sure what’s happening here. If it’s possible, can you send me the entire script?

Sure. You’re going to cringe at my code to make the FPS aspect, but it’s very beta. Lol.

repeat wait() until game:IsLoaded() == true

print("FPS Script - Detected Load")

local UserInputService = game:GetService("UserInputService")

local AttachmentsLibrary = require(game.ReplicatedStorage.Libraries.InvisibleAttachmentsLibrary)
print("FPS Script - Fetched InvisibleAttachemantsLibrary")

local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer

repeat wait() until player.Character ~= nil

UserInputService.MouseDeltaSensitivity = 0
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

print("FPS Script - UserInputService.MouseBehavior, MouseDeltaSensitivity = " .. tostring(UserInputService.MouseBehavior), tostring(UserInputService.MouseDeltaSensitivity))

print("FPS Script - CharacterAdded.")

local character = player.Character

local cameraPart = Instance.new("Part", character:WaitForChild("Head"))
cameraPart.Name = "View"
cameraPart.Transparency = 1
cameraPart.CanCollide = false
cameraPart.Massless = true
cameraPart.Size = Vector3.new(1, 1, 1)

for _, accessory in pairs(character:GetChildren()) do
	if accessory:IsA("Accessory") then
		for _, attachmentName in pairs(AttachmentsLibrary) do
			if accessory:FindFirstChild("Handle") and accessory:FindFirstChild("Handle"):FindFirstChildOfClass("Attachment").Name == attachmentName then
				accessory:Destroy()
			end
		end
	end
end

local cam = game.Workspace.CurrentCamera

RunService.RenderStepped:Connect(function()
	cameraPart.CFrame = cameraPart.Parent.CFrame + Vector3.new(0, 0.27, 0)
	cam.CameraType = Enum.CameraType.Scriptable
	cam.CFrame = cameraPart.CFrame
end)

Also, I have tried setting the MouseBehavior during every frame. Didn’t work.

Try using:

repeat
    UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
    wait()
until UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter.

I think since it is in a loop will force it to change.

It already does print it when I try, but it still doesn’t actually set it.

Try putting that in the RenderStepped then.
(Again not sure but just give it a shot)

Nope, nothing happened. Some weird issue, eh?

Tell me what happens when you try to set it outside of that script. Like as a normal playerscript, not for the gun.

Nothing happens when I put it in another script. :confused:

Have you tried it outside of studio?