Hi all,
I am once again working on my train simulator and I have another problem, that’s why I’m here.
This time, it’s about TweenSerice, and how it’s throwing errors at me and I don’t know what to do.
The purpose of this function is to calculate the Traction of the train based on the maximum traction and the position of the controller as well as update the BodyThrusts in the bogeys accordingly. But of course, forces, especially bigger ones like on trains, don’t increase/decrease instantly but rather smoothly.
Setting the values the hard way works, however I’m having problems making it smooth. I ruled out using for-loops and therefore had to search for an alternative. I found Tweens and wanted to use them, however I came across an error. The error which is thrown at me is “Unable to cast value to object” and directs me to the line where the tweening takes place.
I have tried various solutions from other threads with similar issues, however none of these helped.
I also tried arranging it differently, without success as well.
Also, if there’s a better alternative, feel free to let me know
Parts of the script:
function PhysicsHandler(ChangedValue)
if ChangedValue == "Throttle" then
-- (irrelevant setup of TractionGoal)
local ChangedTable = {
localTraction = 0
}
TweenService:Create(ChangedTable, TweenInfo.new(1), {localTraction = TractionGoal})
-- (irrelevant setting Forces to localTraction)
end
end
Regards, FloribertHD