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: