Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Gun not facing downwards when I look down?

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.