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:

script.Parent.Equipped:Connect(function()
    module:OnEquip(player)
    while true do
        if player.Character:FindFirstChild("NewHead") then
            script.Parent.Union.Orientation.Y = player.Character.Head.Orientation.Y
        end
        wait(0.1)
    end
end)

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:

wait(0.25)

local c0 = game.Players.LocalPlayer.Character:WaitForChild("UpperTorso"):WaitForChild("Waist").C0

function updatewaist()
    local cameralookvectorY = workspace.CurrentCamera.CFrame.lookVector.Y
    local radian = math.asin(cameralookvectorY)
    game.Players.LocalPlayer.Character.UpperTorso.Waist.C0 = c0*CFrame.fromEulerAnglesYXZ(radian,0,0)
end

while wait(1/50) do
    updatewaist()
end

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

Ad

Answer this question