How can i check if 5 seconds have passes without a string value changing, bassically i want a part to disappear after noone clicks for 5 seconds but if you click the time resets
I couldn’t understand what you were saying because of the grammatical issues, by the way based from what I understood, you can use tick()
tick() is outdated and is soon deprecated, a better option is os.clock().
heres a quick snippet of code:
local now = os.clock()
task.wait(5)
local thetime = os.clock() - now
if thetime >= 5 then
print("Around 5 seconds have passed")
print(thetime)
end
Then you can encase it in a clicked event. Or whatever else.
Sorry for explaining it so badly heres what i think is a decent and simplified explanation:
I have a value called LastTouch which is a string valu and has the name of the last player who touched it.
What i need: i need help to make the value go back to “none” if no one touched it for 5 seconds so i essentially i need a clock that checks when have 5 seconds passed since the last touch wait() wont work because if someone touches it before wait() finishes it wont restart the 5 second timer
Just use my idea? with a combination of the string value, an idea:
if the time since last touch was more than 5 seconds and the string value has a player name, then set it to nil.
Your idea isn’t hard to make, just think about it and you’ll find a solution.
Also don’t ask people to write the whole script for you. Again, try experimenting.
I never aks for a full script??? I have already been thinking about this for like 30 mins and thats a lot for sum so small its annoying me so i got on here to ask i had never heard of os.clock before
It does the same thing as tick(), measuring time, but is a little better in my opinion. I guess make a while loop with a separate thread, and make a variable and set it to 0, then increment it by 1 each second, if the time is at 0, reset it back to 5 and set the value to nil.
I would still go for my option though. Heres a quick example:
local player = "RandomGuy" -- Lets just say we had a player already
while true do
local now = os.clock()
task.wait(5)
local thetime = os.clock() - now
if thetime >= 5 and player ~= nil then
print("Around 5 seconds have passed, resetting player.")
print(thetime)
player = nil
end
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.