Hello! I’ve been wondering how do you get “studs per sec” on the formula of “time = distance(magnitude)/studs per sec”?
I tried using this:
local distance = (trainbase.CFrame.Position - n1.CFrame.Position).Magnitude
local speed = distance/200 -- studs/s
local Time = distance/speed
but then the time resulted in 200 seconds.
Then I tried this:
local distance = (trainbase.CFrame.Position - n1.CFrame.Position).Magnitude
local speed = distance/20 -- studs/s
local Time = distance/speed
and then this time the time resulted in 20 seconds and yeah.
I hope you can help me out with this!
1 Like
Studs per second is a measure of studs travelled divided by a time interval. You can’t just arbitrarily divide by a number. You need to measure the time and divide the studs traveled by that interval. You can do this using the delta time parameter in RunService.Heartbeat, some sort of polling, or by measuring the distance between two events using os.time() or tick().
Alternatively, if you have a part that is moving, you can use the magnitude of the Velocity vector to get the speed.
1 Like
Ok nvm I’m just stupid I didn’t need to calculate speed lmao HAHAHA
I used this instead:
local distance = (trainbase.CFrame.Position - n1.CFrame.Position).Magnitude
local speed = 20-- studs/s
local Time = distance/speed
:))
1 Like
I actually didn’t phrase my question well. I thought I had to do some sort of formula to convert 100 studs /s into Roblox world scales but then I already had the speed I wanted (which is 100 studs/sec itself). Thank you for the answer tho! It might help me out in the future
1 Like