Camera turns upside down

script.Parent.Changed:Connect(function()
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CameraSubject = game.Workspace
game.Players.LocalPlayer.Character:FindFirstChildWhichIsA("Humanoid").WalkSpeed = 0
task.wait()
while script.Parent.Enabled == true do
	local Camera = workspace.Camera
		local pos = Vector3.new(workspace["DAF XF"].Body.hiercam.Position.X,workspace["DAF XF"].Body.hiercam.Position.Y,workspace["DAF XF"].Body.hiercam.Position.Z)
	local x = workspace["DAF XF"].Body.hiercam.Rotation.X
	local y = workspace["DAF XF"].Body.hiercam.Rotation.Y-180
	local z = 0
		task.wait()
		if z == not 0 then
			z = 0
		end
	Camera.CFrame = CFrame.new(pos) * CFrame.Angles(math.rad(x),math.rad(y),math.rad(z))
	end
end)
3 Likes

By subtracting 180 degrees, you are flipping the cameras y rotation therfore its causing the camera to turn upside down. Heres the modifications (I hope I didnt do anything wrong)

local Camera = workspace.Camera
local pos = Vector3.new(workspace["DAF XF"].Body.hiercam.Position.X, workspace["DAF XF"].Body.hiercam.Position.Y, workspace["DAF XF"].Body.hiercam.Position.Z)
local x = workspace["DAF XF"].Body.hiercam.Rotation.X
local y = workspace["DAF XF"].Body.hiercam.Rotation.Y
local z = 0

task.wait()

while script.Parent.Enabled == true do
    task.wait()
    if z ~= 0 then
        z = 0
    end
    Camera.CFrame = CFrame.new(pos) * CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))
end
1 Like

Its the same result. I also tried adding not to your script, but still, same result.

Well a solution could be to add this (You can edit the 1’s to match your expectations)

    if y > 1 then
        y = 0
    elseif y < -1 then
        y = -0
    end

Because if the Y value will equal 0 it won’t flip upside down. Hope it helps


It is not as intended…

And did not fix the issue.

Intersting since moving the y value by 0 should not move the y axis of the camera at all.

And I still want the Y axis movable, because you can enter the menu everywhere.

local hiercam = workspace["DAF XF"].Body.hiercam
local pos = Vector3.new(hiercam.Position.X, hiercam.Position.Y, hiercam.Position.Z)
local x = hiercam.Rotation.X
local y = hiercam.Rotation.Y
local z = 0

task.wait()

while script.Parent.Enabled == true do
    task.wait()
    
    if y > 90 then
        y = 90
    elseif y < -90 then
        y = -90
    end

    Camera.CFrame = CFrame.new(pos) * CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))
end

If this doesnt work I dont know what will

You lets say locked the Y axis again and the issue still happens.

Sometimes the code isnt the problem to things, its the things in the game itself, Ive gotten loads of problems and often times it was my problem and the code was fine. The thing that it flips under might be misplacement or smt idk

2 Likes

You can try using the math.atan2() to calculate the y rotation instead.

local y = math.deg(math.atan2(-workspace["DAF XF"].Body.hiercam.CFrame.lookVector.X, -workspace["DAF XF"].Body.hiercam.CFrame.lookVector.Z))

math.deg() is used to convert the results to degress.
Hope this helped. :slight_smile:

Now it does this:

Your code seems fine and as i mentioned eariler the code might not be the problem, I thought a code was a main problem in my game when in reality it was mine. And ru sure thats the only script that interferes with the players camera? Sometimes other codes might mess up.

1 Like

There is also one, but in the A-Chassis Interface.

Yeah your code is fine maybe your A-chassis interface might mess up smt or its misplaced because if the other codes i provided didn’t work its likely something in your game is wrong / another script is interfering with the cam. If I were you I’d double check if everythings right anf check your other script. You could try to remove the script and then run the game and see if the issue still is there and then readd it.

Well this is my custom Mouse Control Camera:

local UIS = game:GetService("UserInputService")
local Body = workspace["DAF XF"].Body
local Camera = workspace.Camera

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		if script.Parent.Values.MouseSteerOn.Value == true then
			game.Players.LocalPlayer.PlayerGui.UI.NotificationText.LocalScript.Value.Value = "Mouse control got Disabled."
			Camera.CameraSubject = Body.Parent.DriveSeat
			Camera.CameraType = Enum.CameraType.Custom
			game.Players.LocalPlayer.Character:FindFirstChild("Head").Transparency = 0
			game.Players.LocalPlayer.Character:FindFirstChild("Torso").Transparency = 0
			game.Players.LocalPlayer.Character:FindFirstChild("Left Arm").Transparency = 0
			game.Players.LocalPlayer.Character:FindFirstChild("Right Arm").Transparency = 0
			game.Players.LocalPlayer.Character:FindFirstChild("Left Leg").Transparency = 0
			game.Players.LocalPlayer.Character:FindFirstChild("Right Leg").Transparency = 0
		else
			Camera.CameraSubject = Body.Camera
			Camera.CameraType = Enum.CameraType.Attach
			game.Players.LocalPlayer.PlayerGui.UI.NotificationText.LocalScript.Value.Value = "Mouse control got Enabled."
			game.Players.LocalPlayer.Character:FindFirstChild("Head").Transparency = 1
			game.Players.LocalPlayer.Character:FindFirstChild("Torso").Transparency = 1
			game.Players.LocalPlayer.Character:FindFirstChild("Left Arm").Transparency = 1
			game.Players.LocalPlayer.Character:FindFirstChild("Right Arm").Transparency = 1
			game.Players.LocalPlayer.Character:FindFirstChild("Left Leg").Transparency = 1
			game.Players.LocalPlayer.Character:FindFirstChild("Right Leg").Transparency = 1
		end
	end
end)

Well from my eyes the second script isn’t either the problem. Either these indexed DAF XF things is the problem or something else is. Another thing COULD be that the -180 at your first code is the problem. If not you could add print statements that will print the Y value each 0.2 or smt and see for yourself why it becomes upside down and do that in both scripts like print(y…“Your script name”) and that in the other as well with these you should be able to spot the problem

about ur camera, is there anything messed up with the settings of it?, have u checked it

edit: i keep forgetting to reply to the owner of this post

Could and wasnt. The -180 is supposed to turn the camera facing the truck.

Hope you read something from this:


When the menu is opened, the game forces the camera to set to Scriptable, so I can access the position and rotation of the camera.

are u changing the cameras position by code or like u connecting the camera with some other part like you know what i mean