Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to get player's join date?

Asked by 5 years ago
Edited 5 years ago

I've tried everything. I've tried devforum posts (an unknown territory for me xD), for example,

Getting the date and subtracting the player's account age from it

which provided these module scripts, and they DO work, but I could not figure out how to subtract the date. First

Second .

I also tried this post from here at scripting helpers:

post

but even this does not work. I updated the code a bit, with a "trust check" error:

game.Players.PlayerAdded:Connect(function(p)
    id = p.UserId
end)
wait(1)
print(id) -- works
local httpservice = game:GetService("HttpService")
local url = "https://www.roblox.com/users/"..id.."/profile"
local html = httpservice:GetAsync(url) -- added
local cut = [[<p class="stat%-title">Join Date</p>%S+<p class="rbx%-lead">(.-)</p>]]
local joindate = html:match(cut);
print(joindate)

Error Message

Does anyone know how to get a player's join date in a string value?

0
Is there a reason you need to get the join date? Also why is id a global variable? When you can just put all this code into the event listener? User#24403 69 — 5y
0
I slapped it together quickly to put it on here, and I want the join date for a dramatic effect :/ TheGreenSuperman 85 — 5y
0
You can't send http requests to roblox so you'll need a proxy. User#24403 69 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

You cannot use the HttpService on Roblox pages as this would be a way to ddos Roblox and you do not need to use the HttpService for this task at all.

The Player includes the AccountAge (in days) which you can use to work out the join date (or very close join date depending upon the server time).

To work this out you first need to convert days -> seconds then take this away from the current time (also in seconds). To convert this into a usable date you can now use os.date .

Example:-

local day = 60 * 60 * 24 -- seconds in a day

game.Players.PlayerAdded:Connect(function(plr)
    local tm = os.time() - (day * plr.AccountAge) -- player join date in seconds
    local date = os.date("!*t", tm) -- convert seconds to date

    print(date.year .. "-" .. date.month .. "-" .. date.day) -- print date
end)

Hope this helps.

0
I always thought you needed string patterns thanks for this it's simpler User#24403 69 — 5y
0
Thanks, this was way more simple than I thought! TheGreenSuperman 85 — 5y
Ad

Answer this question