How can I use a global rotation axis on this control seat?

I’m trying to get this red seat to not roll around when I steer it while facing up or down.

The blue seat was a plane seat that I gutted the GUI out of, as you can see it properly steers horizontally when faced up or down, this is what I wish to achieve for the red seat.

This is the script from the red seat that’s giving me problems.

local move = script.Parent
move.BodyGyro.cframe = move.CFrame
while true do
wait()
speed = script.Parent.MaxSpeed
turnspeed = script.Parent.TurnSpeed

if script.Parent.Steer == 1 then
move.BodyGyro.cframe = move.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,-(turnspeed),0) --turn right
end
if script.Parent.Steer == -1 then
move.BodyGyro.cframe = move.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,turnspeed,0) --turn left
	end
	if script.Parent.Throttle == 1 then
		move.BodyGyro.cframe = move.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(-(turnspeed),0,0) --dive down
	end
	if script.Parent.Throttle == -1 then
		move.BodyGyro.cframe = move.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ((turnspeed),0,0) --pull up
	end
end

I tried borrowing some code from the blue seat to replicate the same behavior like this specific line

BodyGyro.cframe=CFrame.new(0,0,0)*CFrame.Angles(0,math.rad(y),0)*CFrame.Angles(math.rad(x),0,0)

But I couldn’t figure out where to insert it because it just breaks the red seat script, not that it was the right line of code anyway…

So how do I go about this?

CFrame is case sensitive

Should be move.BodyGyro.CFrame

Also BodyGyro is deprecated - Use AlignOrientation instead

Oh yea, I forgot I had to correct that when I copied the code from the other script, still didn’t work though… Could you set it up for me? I never used AlignOrientation before.

I would most likely use “TurnVelocity” for this as its a constant rotating force.

New Script
local Parent = script.Parent

local Turn = Parent.Turn

local TurnSpeed = 4

function SetTurn(...) --// Less Code, Sure
	Turn.AngularVelocity = ...
end

Parent:GetPropertyChangedSignal("Occupant"):Connect(function() --// Prevent Continued Rigidity
	if Parent.Occupant ~= nil then
		Turn.Enabled = true
	else
		Turn.Enabled = false
	end
end)

-----\\

Parent:GetPropertyChangedSignal("Steer"):Connect(function()
	if Parent.Steer == 1 then
		SetTurn(Vector3.new(0, -TurnSpeed, 0)) --// Turn
	elseif Parent.Steer == -1 then
		SetTurn(Vector3.new(0, TurnSpeed, 0)) --// Turn
	else
		SetTurn(Vector3.new(0, 0, 0)) --// Stop If Not Holding
	end
end)

-----//

Parent:GetPropertyChangedSignal("Throttle"):Connect(function()
	if Parent.Throttle == 1 then
		SetTurn(Parent.CFrame.RightVector * -TurnSpeed) --// Forwards
		--SetTurn(Vector3.new(-TurnSpeed, 0, 0))
	elseif Parent.Throttle == -1 then
		SetTurn(Parent.CFrame.RightVector * TurnSpeed) --// Backwards
	else
		SetTurn(Vector3.new(0, 0, 0)) --// Stop If Not Holding
	end
end) 

(My Fault for leaving Crossed Out Code in it, but you can replace Forward and Backwards if with said code if you don’t like that it moves based on its Axis.)

VehicleSeatTest.rbxm (6.4 KB)

This almost works like it should but when I use it long enough I end up tilting off balance when leaning forwards or backwards, I have no idea how this happens.

Left And Right aren’t Bound, so it does that. I’ll see if I can do something about that.

Nvm, this is because you’re combining Turning and Moving Forwards/Backwards. It ends up tilted. Making Rotation based off Left or Right of the part instead of pure speculation with Velocity doesn’t change anything.

Though, if you’d want it that way it would work as following: (Probably)

Parent:GetPropertyChangedSignal("Steer"):Connect(function()
	if Parent.Steer == 1 then
		SetTurn(Parent.CFrame.ZVector * -TurnSpeed)  --// Turn
	elseif Parent.Steer == -1 then
		SetTurn(Parent.CFrame.ZVector * TurnSpeed) --// Turn
	else
		SetTurn(Vector3.new(0, 0, 0)) --// Stop If Not Holding
	end
end)

I did find out about x y z vectors but none of them yielded blue seat results.
seats.rbxl (67.3 KB)
I will send you the seats if you want a closer look at them, the blue seat always stays horizontal even after steering and forwarding at the same time so I’m thinking about gutting the rest of it so I have just the turning. Or if it’s easier you could steal code from the blue seat to get the red one working properly.

What exactly is the problem with one of these seats, could you not just replace “Red”'s Script with “Blue”.

I tried to incorporate some of the code from the blue seat but to no avail. The blue seat works fine but there’s still a bunch of unused properties and if I delete them from the model or the script it stops working. I don’t need BodyVelocity but if I remove it then the script would crash. This particular line could be what’s keeping the blue seat upright but I can’t get it to work the same on the red seat, the closest I got was when it froze all rotation.

seat.BodyGyro.cframe=CFrame.new(0,0,0)*CFrame.Angles(0,math.rad(y),0)*CFrame.Angles(math.rad(x),0,0)

Well I wouldn’t really use while true do to run a script like that, that’s why its crashing.

I tried something like this for the red seat but the output gives me an error saying: Workspace.Folder.VehicleSeat.Drive:24: attempt to index number with ‘TurnSpeed’

local move = script.Parent
local x=0
local y=0

move.BodyGyro.cframe = move.CFrame
while true do
wait()
speed = script.Parent.MaxSpeed
turnspeed = script.Parent.TurnSpeed

if script.Parent.Steer == 1 then
move.BodyGyro.cframe = move.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,-(turnspeed),0)
end
if script.Parent.Steer == -1 then
move.BodyGyro.cframe = move.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,turnspeed,0)
	end
	if script.Parent.Throttle == 1 then
		move.BodyGyro.cframe = move.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(-(turnspeed),0,0)
	end
	if script.Parent.Throttle == -1 then
		move.BodyGyro.cframe = move.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ((turnspeed),0,0)
	end
	
	y=y-script.Parent.Steer.TurnSpeed.Value
	x=x-script.Parent.Throttle.TurnSpeed.Value
	script.Parent.BodyGyro.cframe=CFrame.new(0,0,0)*CFrame.Angles(0,math.rad(y),0)*CFrame.Angles(math.rad(x),0,0)
	
end

The blue seat has a configuration gear with NumberValues inside while my red seat has everything manually set up in the properties of the VehicleSeat. So I removed anything that says data.

I don’t see why you couldn’t really clone the blue seat, turn it red and use that.

All I did was take a free model and delete the gui inside but it still contains roughly half of unwanted code. I wanna at least simplify it as much as possible if all else fails. I’d rather not have an additional configuration gear and I know BodyVelocity only moves the part’s location so I don’t need that either.

And do you want me to re-modernize the blue ones code or something.

I fixed it, check this out!
fixed seat.rbxl (48.2 KB)
Although the seat’s orientation is forced to 0,0,0 before being used the first time but I’ll mess around with that line of code later, I wonder if it’s possible to release the part’s rotation when nobody is sitting on it. BodyGyro does not have an enabled checkbox so it would have to be cloned from the script and deleted from the part somehow.

Just have it set MaxTorque to 0 when its not being used, it’ll make it stop being locked.