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

Gun not facing downwards when I look down?

Asked by 5 years ago
Edited 5 years ago

Hello! My issue today: My gun doesn't look downwards when I do, but instead it just faces forward, even when I look downwards.

Here's my code:

1script.Parent.Equipped:Connect(function()
2    module:OnEquip(player)
3    while true do
4        if player.Character:FindFirstChild("NewHead") then
5            script.Parent.Union.Orientation.Y = player.Character.Head.Orientation.Y
6        end
7        wait(0.1)
8    end
9end)

My characters' heads rotate with the camera. This is in a ServerScript in the gun.

Thanks, MaximussDev.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Found the answer!

You need to adjust the player's UpperTorso CFrame using this code:

01wait(0.25)
02 
03local c0 = game.Players.LocalPlayer.Character:WaitForChild("UpperTorso"):WaitForChild("Waist").C0
04 
05function updatewaist()
06    local cameralookvectorY = workspace.CurrentCamera.CFrame.lookVector.Y
07    local radian = math.asin(cameralookvectorY)
08    game.Players.LocalPlayer.Character.UpperTorso.Waist.C0 = c0*CFrame.fromEulerAnglesYXZ(radian,0,0)
09end
10 
11while wait(1/50) do
12    updatewaist()
13end

Keep in mind, this is just what I did. You can change your 'while wait()' speed to whatever.

Ad

Answer this question