I’m trying to figure out how to make my function stop running it’s code from another function. At the moment I have code that counts up from 0 in increments of 0.01 seconds, and starts the function in an if statement. I plan on making a function that stops this function when a player touches the object I specify. I haven’t found any way to make it stop from another function yet. Any ideas? By the way, here’s the function I’m trying to stop, as well as the if statement that calls it. Thanks!
StartingNum = 0
function StartRace()
while StartingNum >= 0 do
StartingNum = StartingNum + 0.01
wait(0.01)
end
end
if num.Value == 0 then
StartRace()
end
Also, the if statement at the end isn’t by itself. It goes into a countdown function I made. It counts down num.Value from 5 down to 0.
This looks like the underlying issue is not related to being able to stop a function from another. If what you’re trying to do is something like counting time until an event is reached, you can just store the starting time and subtract it from the time when the player reaches the objective. Example pseudocode:
local now_time = tick() -- tick returns the precise current time
finish_line.Touched:Wait() -- assuming it's for a race or something, wait until the finish line is touched
local total_time = tick() - now_time -- the difference is the total time elapsed
But without a clear description of the overall problem, I can’t get much more specific.