I have a simple loop that I'm using to run a non stop check. While it sounds inefficient, I've tried all other ways. My issue is that, if conditions match it's supposed to regenerate something at a timed interval. For example:
while true do
wait(1)
local check = false
-- It gets dicey here
if check == true then
addHealth()
wait(1)
addHealth()
wait(1)
addHealth()
check = false
anotherVar = 7
end
-- Ignore here
if anotherVar == 1 then
check = true
end
end
My issue is, that the addHealth() followed by the wait will actually make the loop wait for 3 seconds, as opposed to waiting for 1 second and then continuing. Is there a way to run a function in the loop, and essentially have the loop not wait for that function to continue?
Just a tack on, if there is a way to do what is above, is it possible to check if said function is already running?

3 comments
Please indent your code
And you want to declare local check outside the loop and before it. Since it's inside, in each iteration you're declaring a local variable named 'check'
https://www.robloxdev.com/articles/Writing-Clean-Code