What do you want to achieve? Keep it simple and clear!
How to make a timer that continues even if the player leaves. Like it gets the current time + The upgrade time but I can’t get it to work.
What is the issue? Include screenshots / videos if possible!
I can’t make a real life timer
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, but most real world time things are unrelated and don’t help
My preferred way of tracking stuff like this is to use tick(), which returns how many seconds it has been since the unix epoch. If you want to make a real-time upgrade timer, you can use tick() + how many seconds the upgrade will take to complete.
local part = script.Parent
local upgrade_time = 60 * 1
local time = tick() + upgrade_time
part.Touched:Connect(function()
if tick() == time then
print("hey!")
else
warn("Hey!")
end
end)
local part = script.Parent
local upgrade_time = 60 * 1
part.Touched:Connect(function()
local Time = tick() + upgrade_time
if tick() == Time then
print("hey!")
else
warn("Hey!")
end
end)
If you want the upgrade to start when you touch the part, do this;
local part = script.Parent
local upgrade_time = 60 * 1
local finishTime;
part.Touched:Connect(function()
if not finishTime then --If there isn't a set finish time
finishTime = tick() + upgradeTime; --Start upgrade timer
elseif tick() >= finishTime then
print("Upgrade finished!");
elseif tick() < finishTime then
warn("Upgrade still in progress!");
end
end)
tick() returns how many seconds have passed since January 1st 1970. When you run it, you’ll get a bigger number each time, because time has gone forward since the last time you ran it.