How can I fix off-timed loops?

My car has a suspension script. Yeah, Alright, here’s the script:

script.Parent.Anchored = true
local function SetupWheel(Wheel:MeshPart)
	if Wheel then
		local Pos = Wheel.Position - script.Parent.Position
		Wheel.CanCollide = false
		game["Run Service"].PreSimulation:Connect(function()
			Wheel.Anchored = true
			local ray = workspace:Raycast(script.Parent.Position, Vector3.new(0, -1, 0) * 50)
			if ray and ray.Distance then
				Wheel.Position = script.Parent.Position + Pos
				if ray.Distance < 5 then
					Wheel.Position = Wheel.Position + Vector3.new(0, 5 - ray.Distance, 0)
				end
			end
		end)
	end
end
for i, obj in pairs(script.Parent.Parent.Wheels:GetChildren()) do
	SetupWheel(obj)
end
script.Parent.Anchored = false
game["Run Service"].PreSimulation:Connect(function()
	local ray = workspace:Raycast(script.Parent.Position, Vector3.new(0, -1, 0) * 50)
	if ray and ray.Distance then
		script.Parent.AssemblyLinearVelocity = Vector3.new(script.Parent.AssemblyLinearVelocity.X, 6 - ray.Distance, script.Parent.AssemblyLinearVelocity.Z)
	end
end)
game.ReplicatedStorage.SendMovement.OnServerEvent:Connect(function(Player, A, D)
	script.Parent.AssemblyLinearVelocity = Vector3.new((D - A) * script.Parent.Parent.Speed.Value, script.Parent.AssemblyLinearVelocity.Y, script.Parent.AssemblyLinearVelocity.Z)
end)
local BP = Instance.new("BodyPosition")
BP.Position = script.Parent.Position
BP.Parent = script.Parent
BP.MaxForce = Vector3.new(0, 0, math.huge)
BP.D = 1200
BP.P = 50000000

anyway, to get to the point, here is my car:
Screenshot 2024-11-29 203345
and here is it moving forwards:
Screenshot 2024-11-29 203347
as you can see, it guesses where it will go next. How can I fix this?

Design the frame with the wheels and get that all working. Then make the car parts all welded together. After that, just weld the car to the frame with the wheels.

i CANNOT weld them. Please tell me how to time these correctly.

No, I’m not going to weld them.

I gave you a script… good luck.

1 Like

The thing is, I do not think I can use welds. Please help me out if you actually work on the devforum, or just give me an unfinished and bad solution, and give up like you did.

I don’t work for Roblox or this forum, sadly. I took a shot at a maybe fix. I don’t have your set up and can’t do much more than take a guess. I’m sure someone knows more about this than me…
“I’ve never seen just moving the wheels like that.”

1 Like

CarR.rbxm (31.2 KB)

This isn’t going to help much. It looks a bit crazy, to be honest. I’ll take a look at what I can do.

1 Like

QARFDWQA.lua (1.0 KB)
here it is, in startergui

This controls the car.
Also, if you meant the car, don’t ask. It’ll be private until I release it.

lol, tact just isn’t you’re stong suit is it? I think I’m done… I actually want to help you but,
I’m not going to reinforce the idea that it’s okay to act like this towards others. Good luck…

You should delete this thread and start over with a better attitude.
Maybe someone else will help you out.

1 Like

Hey uhh, I think i’ve figured out a heavily bugged solution. Can you help fix it?
Problems:

  1. Looks absolutely atrocious moving, still off-timed slightly
  2. Will teleport for a split second before going back to normal, when stopped or started.

code:

script.Parent.Anchored = true
local function SetupWheel(Wheel:MeshPart)
	local Pos = Wheel.Position - script.Parent.Position
	local WOV = Wheel.Orientation
	if Wheel then
		Wheel.CanCollide = false
		game["Run Service"].PreSimulation:Connect(function()
			Wheel.Anchored = true
			local ray = workspace:Raycast(script.Parent.Position, Vector3.new(0, -1, 0) * 100000)
			if ray and ray.Distance then
				if ray.Distance < 5 then
					Wheel.Position = script.Parent.Position + Pos + Vector3.new(0, 5 - ray.Distance, 0) - Vector3.new(script.Parent.AssemblyLinearVelocity.X / script.Parent.Parent.Speed.Value * script.Parent.Parent.Speed.Value / 6.66666666667)
					Wheel.Orientation = WOV + Vector3.new(Wheel.Position.X * 35, 0, 0)
				else
					Wheel.Position = script.Parent.Position + Pos - Vector3.new(script.Parent.AssemblyLinearVelocity.X / script.Parent.Parent.Speed.Value * script.Parent.Parent.Speed.Value / 6.66666666667)
					Wheel.Orientation = WOV + Vector3.new(Wheel.Position.X * 35, 0, 0)
				end
			end
		end)
	end
end
for i, obj in pairs(script.Parent.Parent.Wheels:GetChildren()) do
	SetupWheel(obj)
end
script.Parent.Anchored = false
game["Run Service"].PostSimulation:Connect(function()
	script.Parent.Anchored = false
	local ray = workspace:Raycast(script.Parent.Position, Vector3.new(0, -1, 0) * 100000)
	if ray and ray.Distance then
		script.Parent.AssemblyLinearVelocity = Vector3.new(script.Parent.AssemblyLinearVelocity.X, 4 * 5 - ray.Distance * 5, script.Parent.AssemblyLinearVelocity.Z)
	end
end)
game.ReplicatedStorage.SendMovement.OnServerEvent:Connect(function(Player, A, D)
	script.Parent.AssemblyLinearVelocity = Vector3.new((D - A) * script.Parent.Parent.Speed.Value, script.Parent.AssemblyLinearVelocity.Y, script.Parent.AssemblyLinearVelocity.Z)
end)
local BP = Instance.new("BodyPosition")
BP.Position = script.Parent.Position
BP.Parent = script.Parent
BP.MaxForce = Vector3.new(0, 0, math.huge)
BP.D = 1200
BP.P = 50000000

I will try to be kinder if you were to actually help out, but all you are doing is telling me non-related topics. So stop.
I have a reason I do it this way, so just please follow along instead of go wandering off.

I can see what you’re doing. I suggest sticking to the client as much as possibe with this.
The server clinet combo will have problems keeping up. Also the body is only one part, so ya no need to weld it together. Be nice if that could be attached to the wheels however. That would be lagless.

1 Like

The reason I do not attach it is because it needs easy to edit, custom suspension. I want this to be highly configurable, as I am going to have a ton of vehicles.