Number can't be assigned to?

I’m trying to make a script to constantly check the car’s orientation to see if the car flips and if it does then it would orient itself up.

This is what I’ve tried:

local RunService = game:GetService("RunService")
RunService.Stepped:Connect(function()
	if script.Parent.VehicleSeat.Orientation.X > 80 or script.Parent.VehicleSeat.Orientation.X < -80 then
		script.Parent.VehicleSeat.Orientation.X = 0
	end
	if script.Parent.VehicleSeat.Orientation.Z > 80 or script.Parent.VehicleSeat.Orientation.Z < -80 then
		script.Parent.VehicleSeat.Orientation.Z = 0
	end
end)

I wasn’t too sure if there was a Vector3.new involved but it didn’t work when I tried…

You can’t change individual properties of user data values for instances

You would have to do this:
Instance.Orientation = Vector3.new(x, y, z) -- replace x, y, z with numbers

Vector3’s are immutable, which means they can’t be changed, the individual axes are read-only therefore can’t be set to anything directly. So you’ll want something like

local MAX_X = 80
local MIN_X = -MAX_X

local MAX_Z = 80
local MIN_Z = -MIN_Z

local seat = script.Parent:WaitForChild("VehicleSeat")

RunService.Stepped:Connect(function()
	local current_orientation = seat.Orientation
	seat.Orientation = Vector3.new(
		math.clamp(current_orientation.X, MIN_X, MAX_X),
		current_orientation.Y,
		math.clamp(current_orientation.Z, MIN_Z, MAX_Z)
	)
end)

this will keep it constrained, since math.clamp(x, min, max) returns min if x < min otherwise max if x > max, otherwisw if x is within the defined bounds, then x is just returned

1 Like