artum669
(FireHead)
October 6, 2021, 6:53pm
#1
Hello i need help to make “account age” with “.”
for example:
as you can see 5.30 Years
in my script its only showing without the “.”
for example for me its:
5 years
i read Date/Time Format Strings and still can’t undarstand.
here is my code:
local dateTime = DateTime.fromUnixTimestamp(86400 * accAge)
local yearsOfAge = tonumber(dateTime:FormatUniversalTime('YYYY'+ 'M', 'en-us')) - 1970
i appreciate a lot.
2 Likes
batteryday
(batteryday)
October 6, 2021, 7:25pm
#2
it’s very easy to get the month/day/year from unix timestamp
artum669
(FireHead)
October 6, 2021, 7:27pm
#3
but how can i get in my output for example “5.3” years and not “5”??
can you please show me i am trying do that about a hour please
???
Simple format.
This should work.
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "Leaderstats"
local AgeValue = Instance.new("IntValue",leaderstats)
AgeValue.Name = "Age"
local dateTime = DateTime.fromUnixTimestamp(86400 * plr.AccountAge)
local yearsOfAge = tonumber(dateTime:FormatUniversalTime('YYYY' .. 'M' .. 'en-us')) - 1970
AgeValue.Value = yearsOfAge
end)
1 Like
artum669
(FireHead)
October 6, 2021, 7:59pm
#5
missing argument #3 (string expected)
But tell us where. If you don’t tell us where the errors are we can’t help you
artum669
(FireHead)
October 6, 2021, 8:05pm
#7
artum669
(FireHead)
October 6, 2021, 8:12pm
#8
can you please help i don’t know how to fix that
SOTR654
(SOTR654)
October 6, 2021, 8:20pm
#9
I’m not sure what you want, but try this
local Player = game:GetService("Players").LocalPlayer
print(Player.AccountAge/365) -- in my case it is 5.008, I joined in 2016.
Well surely there is a much easier way to get what you want without all this dateTime stuff you can just do:
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local AgeValue = Instance.new("NumberValue",leaderstats)
AgeValue.Name = "Age"
local playerAge = plr.AccountAge
playerAge /= 365 -- Format players account age to years
AgeValue.Value = playerAge-playerAge % 0.1 -- Truncate number to 1 decimal place
end)
artum669
(FireHead)
October 6, 2021, 8:30pm
#11
and how i can put in my output only 2 decimals?
for example my account age is: “5.0821917808219” and i want in my output be “5.08”
SOTR654
(SOTR654)
October 6, 2021, 8:33pm
#12
you could use math.floor
local Player = game:GetService("Players").LocalPlayer
local Years = math.floor(Player.AccountAge/365 * 100)/100
print(Years)
change 100 by the number of decimal places according to zeros
10 = one decimal
100 = two decimal places
and so with everything
1 Like
artum669
(FireHead)
October 6, 2021, 8:35pm
#13
SOTR654:
print(Years)
thanks a lot i appreciate a lot
1 Like