Cart moving on its own?

I am currently in the making of a cart ride game, i have made a respawn cart button that respawns the cart by cloning it from replicated storage, however when it is spawned the cart zooms forward for a second and then stops.

I think i know the problem im just not sure how to fix it, in the cart there is a script that helps with smoothing the accerleration and deceleration which uses runservice to update the speed correctly, when the cart is moved to the workspace the script starts to run the runservice function which immediately makes the cart move forward, here are both the clone and cart runservice scripts:

Clone

local tpPart = button.TPPart

local respawnTime = 30

local billboardGUI = button.BillboardGui
local billboardText = billboardGUI.TextLabel

local spawningModel = "CartBase" -- put the models name here

local canClone = true

local function onClick()

	if canClone then

		local clonedModel = game.ReplicatedStorage.Carts:FindFirstChild(spawningModel)
		
		clonedModel:PivotTo(tpPart.CFrame)
		clonedModel.Parent = workspace
		canClone = false
		
		for i = respawnTime, 0, -1 do

			billboardText.Text = i

			wait(1)
		end

		billboardText.Text = "Respawn"

		canClone = true

	end
end

button.ClickDetector.MouseClick:Connect(onClick)```

**RunService**
```local cart = script.Parent

local seat = cart.VehicleSeat

local RunService = game:GetService("RunService")

local Seat = cart.VehicleSeat

local BackLeft = cart.LB
local BackRight = cart.RB

local FrontLeft = cart.LF
local FrontRight = cart.RF

local Throttle = 2


	
	RunService.Heartbeat:Connect(function(Delta)


		local ThrottleGoal = Seat.ThrottleFloat
		Throttle += (ThrottleGoal - Throttle) * math.min(Delta * Seat.TurnSpeed, 1)
		local Torque = Seat.Torque
		local Speed = Seat.MaxSpeed * Throttle

		-- apply the speed & torque to the wheels here
		FrontLeft.Wheel.WheelContraint.MotorMaxTorque = Torque
		FrontRight.Wheel.WheelContraint.MotorMaxTorque = Torque

		BackLeft.Wheel.WheelContraint.MotorMaxTorque = Torque
		BackRight.Wheel.WheelContraint.MotorMaxTorque = Torque

		FrontLeft.Wheel.WheelContraint.AngularVelocity = -Speed 
		FrontRight.Wheel.WheelContraint.AngularVelocity = Speed 

		BackLeft.Wheel.WheelContraint.AngularVelocity = -Speed
		BackRight.Wheel.WheelContraint.AngularVelocity = Speed

	end)

	

here is also a video so that you can understand the problem easier:

1 Like

You’re applying torque after you spawn it here

Did you mean to do something else?

this script was made from a tutorial for smoothing out the acceleration and deceleration thats all i needed, what do you mean by that?

1 Like

Oh nevermind I thought that was accelerating the cart at the start nevermind

Maybe disable the constraints until they hop in the cart (only for the first time I guess)

Are there any forces that are not zero when the assembly is cloned?

local cart = script.Parent
local seat = cart.VehicleSeat
local RunService = game:GetService("RunService")

local Throttle = 0 -- Start with 0 throttle to prevent immediate movement

local function updateWheels(Delta)
	local ThrottleGoal = seat.ThrottleFloat
	Throttle += (ThrottleGoal - Throttle) * math.min(Delta * seat.TurnSpeed, 1)
	local Torque = seat.Torque
	local Speed = seat.MaxSpeed * Throttle

	-- apply the speed & torque to the wheels here
	cart.LF.Wheel.WheelConstraint.MotorMaxTorque = Torque
	cart.RF.Wheel.WheelConstraint.MotorMaxTorque = Torque
	cart.LB.Wheel.WheelConstraint.MotorMaxTorque = Torque
	cart.RB.Wheel.WheelConstraint.MotorMaxTorque = Torque

	cart.LF.Wheel.WheelConstraint.AngularVelocity = -Speed 
	cart.RF.Wheel.WheelConstraint.AngularVelocity = Speed 
	cart.LB.Wheel.WheelConstraint.AngularVelocity = -Speed
	cart.RB.Wheel.WheelConstraint.AngularVelocity = Speed
end

-- Only start updating the wheels when a player sits in the seat
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		RunService.Heartbeat:Connect(updateWheels)
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.