How to make a timer which determines what an item is called

I want to create a cooking system where if its the food, lets a say a steak in this example, has different results based on how long its in there such as

5 seconds
10 seconds
Medium Rare
15 seconds
Well done

and at any moment the user can press a button which ends the timer and does something with the rarity of the steak

Would tick work in this scenario, if so how?

It could work as such:

local FoodClass = {};
FoodClass.__index = FoodClass;

function FoodClass:Cook()
    self.Cooking = true;
    self.CookingBeginTick = tick();

function FoodClass:EndCook()
    if self.Cooking == false then return end;
    if not self.CookingBeginTick then return end;

    self.Cooking = false;

    local CookTime = tick() - self.CookingBeginTick;

    if CookTime > 5 then
        self.Status = 'Rare'
    elseif CookTime > 10 then
        self.Status = 'Medium Rare'
    elseif CookTime > 15 then
        self.Status = 'Well Done'
    elseif CookTime > 20 then
        self.Status = 'Burn'

    self.CookingBeginTick = nil;

function FoodClass.New(Name, Status)
    local self = {
        __index = FoodClass;

        Name = Name;
        Status = Status;
        Cooking = false;

    setmetatable(self, FoodClass)

    return self

return FoodClass;

Now you can utilize this class

local FoodClass = require() -- Require Module Here

-- Create Food Item 
local FoodItem = FoodClass.New('Steak', 'Raw')


print(FoodItem.Status) ---> Prints 'Well Done' 

You can use an OOP approach (what I did above) to script this cooking system. It’s what I would recommend in general. You can make it its more customizable (right now I just did the basics, feel free to add on).

1 Like

That looks like what im looking for! Thank you so much!

1 Like