I’m looking for how I could begin to create an engine which will over time decrease in health when the vehicle moves, I’m not looking for entire code but just a lead into the right direction or how I could begin to approach this.
You could use an attribute, intValue, or even a table to represent the vehicles health and if its moving. I would probably use two bindable events, one for when the vehicle moves and one for when it stops moving, I would set it up like this.
Car Moves (could be the velocity changing to something over 0.)
Fire bindable event correlating to the car moving.
Other script picks up the event and decreases the engine’s health value (previous intvalue, attribute, or table value, using a while loop, runservice etc)
Once the move ended bindable event is fired disconnect the function
Great idea. One more thing I’d throw out is having a while loop that can detect when the car is moving and decrease the engine health relative to its speed using Velocity.Magnitude or AssemblyAngularVelocity on a part in the vehicle.
But what if the vehicle starts rolling down a hill quickly due to gravity? The engine is doing no work yet the script will wear out the engine health because it detects the vehicle moving fast. To fix this I’d have another part of the script runs a while loop while the VehicleSeat math.abs(Throttle) is greater than 0, and adds 1 to a number variable called “push” or something, that resets to zero when throttle input stops.
By comparing the cumulative throttle to the vehicle’s speed, we can ascertain how much of the vehicle’s speed is caused by engine effort and use that value to detect how much engine health should be reduced