UserInputService.MouseBehaviour not working?

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?

I have actually tried it out but for me…

This does not work:-

local userinputservice = game:GetService("UserInputService") userinputservice.MouseBehavior = Enum.MouseBehavior.LockCenter

But this does:-

local userinputservice = game:GetService("UserInputService")

game:GetService("RunService").Heartbeat:Connect(function(dt)
    userinputservice.MouseBehavior = Enum.MouseBehavior.LockCenter 
end)
2 Likes

Didn’t work. Hmmm… :slightly_smiling_face:

So it isn’t just me!

However, this did work. We have made history, ladies and gentlemen.

Thanks so much!

1 Like

I used “UserInputService.MouseBehavior = 1” and it worked for me, Idk why. There’s a table here for the different number codes: MouseBehavior | Roblox Creator Documentation

Sorry for my lack of formality, new to dev form and am kinda rushing now.

1 Like

Hello, it doesn’t work for me :frowning: is there another way?

I struggled with this problem for a while. I managed to solve it, however, by setting the workspace camera to Camera.CameraType Fixed (it does appear to be working with Custom as well though), and in Starterplayer setting the CameraMode to LockFirstPerson.

This did not work at first, untill I removed all my code that modified UserInputService.MouseBehaviour and player.CameraMode. So removing all the code
that modified it solved my problem.

To be able to move the mouse freely at times, I use a textButton in a ScreenGui with its property Modal set to true.

Hope this helps!