Ive been trying to make this script where the camera will follow the players mouse movement (EX: if the mouse moves up, so does the camera)
But no matter what i try it never works out. Heres my current script:
repeat task.wait(1) until game:IsLoaded() task.wait(1)
local rs = game:FindService("RunService") or game:GetService("RunService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local camera = game.Workspace.CurrentCamera
local UIS = game:FindService("UserInputService") or game:GetService("UserInputService")
local bool = false
local char = plr.Character
local rootPart = char.HumanoidRootPart
UIS.InputBegan:Connect(function(input, chat)
if chat then return end
if input.UserInputType == Enum.UserInputType.MouseButton3 and bool == false then
camera.CameraType = Enum.CameraType.Scriptable
rs.Heartbeat:Connect(function(fps)
local MPos = mouse.Hit.p
camera.CFrame.Position.LookVector = MPos.LookVector
end)
end
end)
Ive looked all over devforum, and there are some helpful posts but everything ive tried hasnt worked. Help is appreciated, thank you for your time
if not game:IsLoaded() then
game.Loaded:Wait()
end
local rs = game:FindService("RunService") or game:GetService("RunService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local camera = game.Workspace.CurrentCamera
local UIS = game:FindService("UserInputService") or game:GetService("UserInputService")
local bool = false
local char = plr.Character
local rootPart = char.HumanoidRootPart
UIS. InputChanged:Connect(function(input, chat)
if chat then return end
if input.UserInputType == Enum.UserInputType.MouseButton3 and bool == false then
camera.CameraType = Enum.CameraType.Scriptable
rs.RenderStepped:Connect(function(fps)
local MPos = mouse.Hit.p
camera.CFrame.Position.LookVector = MPos.LookVector
end)
end
end)
So, for security reasons, you can’t lock a player’s actual mouse in whatever UDim2 position it was last at, though the need to do so isn’t too uncommon with certain battle and gameplay mechanics
My best advice if you want to achieve this is to make a custom mouse cursor with an ImageLabel, having it constantly set to the position of the player’s mouse, while using the MouseIconEnabled property of UserInputService to make the real mouse invisible. Then when you want to “lock” the mouse, make the ImageLabel stop moving
When your mouse is locked, you would set toggle to true. Then, when you’ve unlocked the mouse, you can set it back to false. RunService will still run, but it’ll only do stuff when toggle is set to false. This is the best way to have a toggling system with RenderStepped