So i’m trying to make it so that when a player fires a gun, they look at the mouse aka the target position. Now I’m having trouble doing this, my script below is how i attempted it. Basically what i did was try to make the HRP rotate towards the mouse but it isn’t working. How would I do this?
char.HumanoidRootPart.CFrame = CFrame.Angles(0,0,math.rad(tonumber(mouse.Hit.p)))
It keeps coming back saying “Expected number got Vector3” so I added the tonumber function but that seems to also not work.
Kensizo
(Kensizo)
May 6, 2020, 2:20pm
#2
This post has been written about too many times.
Please do not make posts without looking if there was a post similar to the one you’ve already posted about.
Here is a solution provided by CleverSource, for this same issue, but very descriptive and correctly written;
I have made a simple local script for you which makes the player’s head and torso follow the player’s mouse. I’ll have a working example below, the .rbxl file provided, and the code! I hope this helps. If you have any questions feel free to ask me.
Code:
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local PlayerMouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local Character = Player.Character or Player.CharacterAdded:Wait()
local H…
3 Likes
I know there’s already a solution above but i just wanted to point out that you should be using .Position
instead of . p
.