Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would you go by making twitter codes expire?

I know how to make a twitter code GUI and how to make it detect if they already used it or not, but I want to know how many games make it so it expires at an exact date. Expiring isn't hard, but I don't know they make the code expire without having to shutdown all servers with editing the script. How do they make them expire without having to shutdown after updating?

I'm not asking for code, but at least some small examples or some links could help me out. Thanks.

3 comments

0

DataStores

0

That's such a vague response. Obviously it's something to do with datastores but how do you make it so you set it to expire, lets say after 24 hours or something?

1

such a vague question

1 answer

Using mathematical calculations, you can "expire" a code at a certain date by using the following. Simply adapt the code (I did an example of how to adapt it below) and go from there.

-- Calculating time
function CurrentDate(z)
    local z = math.floor(z / 86400) + 719468
    local era = math.floor(z / 146097)
    local doe = math.floor(z - era * 146097)
    local yoe = math.floor((doe - doe / 1460 + doe / 36524 - doe / 146096) / 365)
    local y = math.floor(yoe + era * 400)
    local doy = doe - math.floor((365 * yoe + yoe / 4 - yoe / 100))
    local mp = math.floor((5 * doy + 2) / 153)
    local d = math.ceil(doy - (153 * mp + 2) / 5 + 1)
    local m = math.floor(mp + (mp < 10 and 3 or -9))
    return y + (m <= 2 and 1 or 0), m, d
end

function CurrentTime(hoursOffset)
    local unixTime = math.floor(os.time()) - (60*60*(hoursOffset or 0))

    local hours = math.floor(unixTime / 3600 % 12)
    local minutes = math.floor(unixTime / 60 % 60)
    local seconds = math.floor(unixTime % 60)

    local year, month, day = CurrentDate(unixTime)

    return {
        year = year,
        month = month, 
        day = day,
        hours = hours,
        minutes = minutes < 10 and "0" .. minutes or minutes,
        seconds = seconds < 10 and "0" .. seconds or seconds
    }
end

local date = CurrentTime(-7)

print(date.month .. "/" .. date.day .. "/" .. date.year .. " " .. date.hours .. ":" .. date.minutes .. ":" .. date.seconds)

-- Codes
twitterCode = "TwitterYay"

if date.month == 3 and date.day == 5 and date.year == 2018 then
	twitterCode = "TwitterYay2"
end

Hopefully you get how I adapted it from the original time script, if not, here is a value directory:

date.month = month number
date.day = day of the month
date.year = number of the year
date.hours = hour of the day
date.minutes = minute of the day
date.seconds = second of the day

2 comments

0

Can't you just use os.date() in a data store to do this a lot easier?

0

os.date() can't be used for this type of application

This discussion is preserved as it was. New answers, comments, and votes are closed.