I have been trying to figure out how to make the player face the mouse, i am currently new to BodyGyro and other things.
01 | local player = game.Players.LocalPlayer |
02 | local character = player.Character |
03 | local torso = character.LowerTorso |
04 | local BodyGyro = Instance.new( "BodyGyro" , torso) |
05 | local bodyGyro = torso.BodyGyro |
06 | local mouse = player:GetMouse() |
07 |
08 |
09 | mouse.Move:connect( function () |
10 | bodyGyro.CFrame = CFrame.new(torso.Position, mouse.Hit.p) |
11 | end ) |
01 | local player = game.Players.LocalPlayer |
02 | local gyro = nil |
03 | local mouse = player:GetMouse() |
04 | mouse.TargetFilter = game.Workspace.Level |
05 | local runService = game:GetService( 'RunService' ) |
06 | local character = player.Character or player.CharacterAdded:wait() -- use this |
07 |
08 | local function onCharacterAdded(character) |
09 | local head = character:WaitForChild( 'Head' ) -- Use head for R15 |
10 | gyro = Instance.new( 'BodyGyro' ) |
11 | gyro.P = 50000 |
12 | gyro.MaxTorque = Vector 3. new( 0 , 10000 , 0 ) |
13 | gyro.Parent = head |
14 |
15 | local humanoid = character:WaitForChild( 'Humanoid' ) |
That's my script for this. Hope this helps :)
Put the BodyGyro in HumanoidRootPart, also this should be converted into FilteringEnabled
RunService = game:GetService('RunService') Players = game:GetService('Players') Player = Players.LocalPlayer Mouse = Player:GetMouse() Char = Player.Character if not Char then Player.CharacterAdded:Wait() Char = Player.Character end
RootPart = Char:WaitForChild('HumanoidRootPart')
RunService.Stepped:connect(function()
1 | local MousePos = Mouse.Hit.p |
2 |
3 | local lookVector = Vector 3. new(MousePos.X,RootPart.CFrame.Y,MousePos.Z) |
4 |
5 | RootPart.CFrame = CFrame.new(RootPart.CFrame.p,lookVector) |
end)
I think your problem is in local mouse = player:getMouse() as the computer doesn't know what player. If this script is in a starterpack or startergui then you could do script.Parent.Parent:GetMouse() which is what worked for my script