You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? i want to, when pressed W the Wagon just advance and when pressed S or stopped from pressing W it stops moving
What is the issue? it blocks for some reason
**What solutions have you tried so far?**I tried looking on internet
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--\\\ Services ///
local WAGON = script.Parent
local Cart = WAGON:WaitForChild("Cart")
local Base = Cart:WaitForChild("Base")
local Driver_Seat = Cart:WaitForChild("VehicleSeat")
local Wheels = WAGON:WaitForChild("Wheels")
local Motors = {}
local Driving = false
-- \\\ Functions ///
function INIT()
for _, object in pairs(Wheels:GetDescendants()) do -- get motors
if object:IsA("HingeConstraint") then
print('hotspot')
table.insert(Motors, object)
end
end
end
function PreventFling()
task.wait(.1)
Base.Anchored = not Base.Anchored
end
function OnDriven()
print(Driver_Seat.Throttle)
task.wait(.5)
if Driver_Seat.Throttle ~= 1 and Driver_Seat.Throttle ~= 0 then return end -- check if its advancing or stopping to advance
if Driver_Seat.Throttle == 1 then -- when advancing
Driving = true
elseif Driver_Seat.Throttle == 0 then -- when going back
Driving = false
end
if Driving then
for _, motor in pairs(Motors) do
motor.AngularVelocity = 100
end
else
for _, motor in pairs(Motors) do
motor.AngularVelocity = 0
end
end
end
INIT()
Driver_Seat:GetPropertyChangedSignal("Occupant"):Connect(PreventFling)
Driver_Seat:GetPropertyChangedSignal("Throttle"):Connect(OnDriven)
What are the Torques on your wheel HingeConstraints? Try a number like 30000 for a ‘normal’ sized car. For a bigger vehicle you probably need more Torque. Fine tune it to where the car works best. Too high may cause the wheels to shake when the vehicle is just sitting.
Are your HingeConstraints set to Motor?
Are your HingeConstraints aligned properly? If you have the Attachments all facing the same way (left to right) then your code should work. If you have them all facing outward or inward then you’ll have to make the left HingeConstraints AngularVelocity negative and the right HingeConstraints AngularVelocity positive.
Are any of your car Parts Anchored?
Put the car just off the ground in Studio and Anchor one of the frame Parts. Try driving it and see what your wheels are doing. If they rotate and steer properly then it’s probably a torque problem (the car is heavier than the wheels can drive). If the wheels are rotating forward on one side and backwards on the other then it’s an AngularVelocity issue.
Did you not see in the code the anti fliing thing it unanchor when a player seats and anchor it back when the player isnt sitting anymore because the wagon gets off the track when the player seats on it for the maxtorque it was to 5K changed it to 30K like you said still dosen’t work
This is the only issue you mentioned. You didn’t say if it was moving a bit then was stopping, or if it was never moving, which is why I questioned if any of the other parts were Anchored.
Looking at the video your print of Throttle is showing 0 then 1 then 0 then 1. Are you holding the W key all the time during the video? If you are holding down the W key there is an issue with your code that is resetting it back to 0.
Why have the Driving boolean anyway? You could do it very easily without using it at all since it’s not used in any other part of your code:
function OnDriven()
print(Driver_Seat.Throttle)
task.wait(.5)
if Driver_Seat.Throttle ~= 1 and Driver_Seat.Throttle ~= 0 then return end --
if Driver_Seat.Throttle == 1 then -- when advancing
-- Driving = true (remove this line)
for _, motor in pairs(Motors) do
motor.AngularVelocity = 100
end
elseif Driver_Seat.Throttle == 0 then -- when going back
-- Driving = false (remove this line)
for _, motor in pairs(Motors) do
motor.AngularVelocity = 0
end
end
--[[ this section isn't needed with the above code
if Driving then
for _, motor in pairs(Motors) do
motor.AngularVelocity = 100
end
else
for _, motor in pairs(Motors) do
motor.AngularVelocity = 0
end
end]]
end
Also you should have a little bit of space between the sliders you have (to keep it from derailing) and the rails. Also make the sliders Friction = 0 so they don’t slow the cart down if they touch.
Select one of the wheel HingeConstraints and take a screenshot of all it’s Properties so we can see what you have them set to.
Please answer more than just one of the questions I asked…
Does your Throttle input change while you are holding W, or does it stay at 1?
Did you try moving the sliders away from the rails and making their Friction = 0?
The white pieces you have that hold on the sides of the tracks.
If the friction is high it’ll affect your wagon.
Click the CustomPhysicalProperties button in each of those white Parts and set the Friction to 0.
Have a look at this tutorial model I made for other people to look at. It works well at very high speeds as well. Train test, bogies with tilt (VectorForce or Hinges).rbxl (191.8 KB)