Scripting problem

is this the whole code?? This text will be blurred

1 Like

No, buts its the code for what I’m trying to achieve, I just want to turn/steer the wheel when I change the vehicle seat values.

local att = script.Parent.Body:WaitForChild("AttachmentFL")
while wait(.1) do
   if script.Parent.VehicleSeat.Steer == 1 then

     	att.Orientation = Vector3.new(0,30,-90)
	
     	print("it worked")
	
   end
end

try this
dont check for steerfloat you gotta check for the steer value

How? can you explain more on that?

i dont know how to explain that sorry but anyways if you check the vehicle seat there is a value called throttle and steer those get updated when player inputs
so

if seat.Steer==1 then
   --car go right
elseif seat.Steer==-1 then
   --car go left
elseif seat.Steer==0 then
   --car no turn
end

im not sure if my code is correct or no cuz i dont remember which one turns which way lol

That’s not how you do turning with constraints, Usually with constraints you will utilize hinge constraints then set the target angle like so, not change the attachment orientation:

--input steer is the steer throttle goes from [-1,1]
constraint.TargetAngle = ChassisStats.TurnRadius.Value * inputSteer -- hinge

I suggest looking at the basic car kit (tells you how to rig it mostly) and the open source car chassis (complete rig with some neat features and easy to read and fix up code in my opinion) for how constraint vehicles work.

Another option is Sleitnicks tutorial which is more comprehensive for both rigging the car and coding it.

I tried that just now, It doesnt seem to work…

oh it seems you use cylindrical constrains as my way wont work so look at @dthecoolest

@slietnick, Says to change the orientation of the attachment, to change the wheel direction in his tutorials (I cant get help with this from his tutorial though, because I’m making a slightly different chassis)

could you explain on how your different chassis is so i could help

also i do think its good that you show the whole code…

I’m using cylindrical constraints to power the wheels, and changing the front two wheels attachments orientations to change the direction the vehicle goes in.

i really think you should show the code

Its in the first post, That’s the whole code, buts its for the FL wheel

try this

local steer =30
while true do

        if seat.Steer == 1 then
    		AttachmentFL.Orientation = Vector3.new(0, steer, -90)
    		AttachmentFR.Orientation = Vector3.new(0, steer, -90)
    	
    	elseif seat.Steer == -1 then
    		AttachmentFL.Orientation = Vector3.new(0, -steer, -90)
    		AttachmentFR.Orientation = Vector3.new(0, -steer, -90)
    	
    	elseif seat.Steer == 0 then
    		AttachmentFL.Orientation = Vector3.new(0, 0, -90)
    		AttachmentFR.Orientation = Vector3.new(0, 0, -90)
    	end
     wait()
end

I don’t know if putting it in a while loop will help, that’s just a while loop, how will it help with the if statement not working?

Because seat.Steer doesnt work.

rather than multiple if you just add one if and others are elseif

how does seat.Steer doesnt work?!?!

I don’t know, but I tried it and it doesnt work.

Basically you need to tell when the function is fired,or when it can be fired.Its basically not a looped function so it functions only once and it does not work probably as the game may not load and the script loaded before.You can fix it by this script:

local att = script.Parent.Body:WaitForChild("AttachmentFL")


local function changeorienttion()
    if script.Parent.VehicleSeat.SteerFloat == 1 then
        local success,errormessage = pcall(function()
            att.Orientation = Vector3.new(0,30,-9)
        end)
        if success then
            print("it worked")
        else
            print(errormessage)
        end
    end
end

You basically need to tell when to fire it to.
Use this line in script to fire it.

changeorientation()

This may work, try it

why do you pcall? i dont think that needs pcall?