Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make player face the mouse?

Asked by
Jirozu 71
8 years ago

I have been trying to figure out how to make the player face the mouse, i am currently new to BodyGyro and other things.

01local player = game.Players.LocalPlayer
02local character = player.Character
03local torso = character.LowerTorso
04local BodyGyro = Instance.new("BodyGyro", torso)
05local bodyGyro = torso.BodyGyro
06local mouse = player:GetMouse()
07 
08 
09mouse.Move:connect(function()
10    bodyGyro.CFrame = CFrame.new(torso.Position, mouse.Hit.p)
11end)

4 answers

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago
01local player = game.Players.LocalPlayer
02local gyro = nil
03local mouse = player:GetMouse()
04mouse.TargetFilter = game.Workspace.Level
05local runService = game:GetService('RunService')
06local character = player.Character or player.CharacterAdded:wait()-- use this
07 
08local 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 = Vector3.new(0, 10000, 0)
13    gyro.Parent = head
14 
15    local humanoid = character:WaitForChild('Humanoid')
View all 35 lines...

That's my script for this. Hope this helps :)

0
Doesnt work for me, sorry. Jirozu 71 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Put the BodyGyro in HumanoidRootPart, also this should be converted into FilteringEnabled

Log in to vote
0
Answered by 4 years ago

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()

1local MousePos = Mouse.Hit.p
2 
3local lookVector = Vector3.new(MousePos.X,RootPart.CFrame.Y,MousePos.Z)
4 
5RootPart.CFrame = CFrame.new(RootPart.CFrame.p,lookVector)

end)

0
there, hope it helps. also put this in StarterPlayer.StarterPlayerScript and this mst be a local script happy_gagarara12 13 — 4y
Log in to vote
-1
Answered by 8 years ago

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

0
No, he's doing it right. Player is a variable he has already. AstrealDev 728 — 8y
0
Maybe it's because im using r15? Jirozu 71 — 8y

Answer this question