Using :GetMouse()
in a Local Script, you can get the Player's Mouse. In this instance, we can use Mouse.Hit
and Mouse.Target
. Mouse.Hit
returns the CFrame of the Cursor. In simpler terms, where the Mouse is pointing. Mouse.Target
returns the object the object the Mouse is pointing to. In this instance, we want to use Mouse.Hit
to get the CFrame of the Mouse. When we do that, we can set our HumanoidRootPart's CFrame to the CFrame of the Mouse. It would look something like this.
01 | local Player = game.Players.LocalPlayer |
02 | local Character = Player.Character or Player.CharacterAdded:Wait() |
03 | local HumanoidRootPart = Character:WaitForChild( "HumanoidRootPart" ) |
04 | local UserInputService = game:GetService( "UserInputService" ) |
05 | local Mouse = Player:GetMouse() |
07 | UserInputService.InputBegan:Connect( function (input, gameProcessed) |
08 | if gameProcessed then return end |
09 | if input.KeyCode = = Enum.KeyCode.Q and Mouse.Hit then |
10 | local MouseCFrame = Mouse.Hit |
11 | HumanoidRootPart.CFrame = MouseCFrame |