I’m gonna be straight, I’m trying to create a overturning script, much like Jailbreak, but automatic, but it’s not working, it prints everything it has to, but doesn’t overturn it, I need help, if it’s normal (0,0,0) it prints everything okay, as it has to, but when it’s overturned it prints overturned and solved even though it’s not overtiring it
local car = script.Parent
local seat = car.VehicleSeat
local orientation = seat.Orientation
local XO = orientation.X
local YO = orientation.Y
local ZO = orientation.Z
local position = seat.Position
local ZP = position.Z
local XP = position.X
local YP = position.Y
while true do
wait(0.1)
print("Checking")
if ZO == math.clamp(150,-150,-0) then
wait(1)
print("Overturned")
XP = XP
ZP = ZP
YP = YP+25
wait(0.1)
XO = 0
ZO = 0
YO = YO
print("Solved")
elseif XO == math.clamp(150,-150,-0) then
wait(1)
print("Overturned")
XP = XP
ZP = ZP
YP = YP+25
wait(0.1)
XO = 0
ZO = 0
YO = YO
print("Solved")
else
print("Nothing wrong")
return end
end
The script is supposed to check every 0.1 seconds the orientation of the part, if it’s between 150,-150,0 it on either the Z/X axis it will change the position to it’s currrent position but 25 studs higher on the Y axis, and then wait0.1 seconds and overturn it by putting it’s Y axis at its current one and it’s Z and X at 0, 0, but the thing is that it prints everything it has to, but doesn’t change anything, and also the seat is the PrimaryPart of the model, thanks in advance for your help
Can you list the steps that your script is supposed to take as regular words, that way someone can compare that to your script to see whats wrong. Sometimes if a script is only slightly broken you can figure out what the writer meant and fix it without this, but I can’t figure out what you mean by this script, so I need an explanation.
This makes a copy of the orientation values, checking these will not give you the current value. You need to do seat.Orientation.X each time you want the current X value.
local XO = orientation.X
local YO = orientation.Y
local ZO = orientation.Z
This does not check a range, it only checks if Z0 is equal to the result of the math on the right, which is also always the same number.
if ZO == math.clamp(150,-150,-0) then
For reference, what you probably meant was this, but I’ll show you a better way:
if ZO > -150 and ZO < 150 then
To check if something is upside down, meaning its Y axis is not pointing up, you can do this. You’ll have to trust me on the math:
if car.VehicleSeat.CFrame.UpVector:Dot(Vector3.yAxis) < 0 then
--Car seat is upside down
To flip the car the right way up, you can set its seat CFrame back to default:
However, this will also reset its position, so you need to save the position and add it back. There is another CFrame constructor that takes a position that can do this:
car.VehicleSeat.CFrame = CFrame.new(car.VehicleSeat.Position) --default orientation with old position
I want the Y axis (the one that faces side to side) to be the same as before you overturned, like if overturned I was at 90 degrees, after the script fires look still at 90 degrees, wouldn’t this make it look at 0,0,0?
Also, where do I put it? And thanks for your help
Edit: Everything worked, the only problem is that now the front wheels are into the car (I’m currently using an a-chassis)
Update, the script works, even though the tires get into the car, I’m using an a-chassis car, from this tutorial and the other problem is that after the car is overturned, the script doesn’t fire anymore, other than that everything works fine, here’s the updated script:
local car = script.Parent
local seat = car.VehicleSeat
local XO = seat.Orientation.X
local YO = seat.Orientation.Y
local ZO = seat.Orientation.Z
local position = seat.Position
local ZP = position.Z
local XP = position.X
local YP = position.Y
while true do
wait(0.1)
print("Checking")
if seat.CFrame.UpVector:Dot(Vector3.yAxis) < 0 then
print("Overturned")
wait(2.5)
seat.CFrame = CFrame.new(seat.Position)
print("Solved")
else
print("Nothing wrong")
return end
end
Cframing a model that has Constraints in it will cause issues because the car doesn’t ‘move’ there, it is snapped there and Constraints don’t like that.
Try MoveTo instead, or Tweening.
Or you may have to weld the wheels to the car before it flips, then disable the weld after it flips.