How do i check how long something is there like lets say how long a boolvalue is set true and if its set true for like 10 seconds it prints something.
✓ ANSWER ACCEPTED
How do i check the time of how long something is set true or false?
1 answer
✓ Accepted answer
You can use tick() to get the difference between the times
At the top of the script, you can do this:
local startTime
Then when you set the value to true, you can do this:
bool.Value = true
startTime = tick()
And then when you set it to false, you can check if the difference between the new tick and the start time is more than 10
bool.Value = false
local timeTaken = tick() - startTime
if timeTaken >= 10 then
print("10 seconds later")
end
If you just wanted to do all this whenever the value is changed, it would look something like this:
local bool = --set to boolvalue
local startTime
bool.Changed:Connect(function(newVal)
if newVal == true then
startTime = tick()
else
local timeTaken = tick() - startTime
if timeTaken >= 10 then
print("More than 10 seconds")
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thank you!