What should I do to have a character age system in my game?

In my game I want there to be a character created value in a stat menu.
Example:
image
This is just placeholder text however and it doesn’t work.

Whats the best way to figure out when a players character was made? I was thinking something to do with tick() or os.time() all help is greatly appreciated!

2 Likes

You could track the start time (when the player first creates the character) in a table and then save that to a datastore. Then every time they reset/leave the game, you can add the current time onto the variable.

Something like this:

	local player --the player
	local playTime = {} --table to hold player in-game time

	--initializing the time when they first create the character
	playTime[player] = {
		initialTime = workspace:GetServerTimeNow(),
		totalPlayTime = 0,
	} 

	---below is for when you reset/leave the game, to update the time
	playTime[player].totalPlayTime += (workspace:GetServerTimeNow() - playTime[player].initialTime)

Also remember to set initialTime to workspace:GetServerTimeNow() every time the player spawns into the game, so you can track for that session

2 Likes

I wasn’t referring to playtime but rather the actual time the character was made.
Example: I make a character and only play for 1 hour then log off for a week and come back. The time should say Character Created: 1 Week Ago

1 Like

Ohhh that’s even easier to do. Just track whenever the player created the account using workspace:GetServerTimeNow() then save that value. And when you want to display when it was created, just retrieve that stored value and do print(workspace:GetServerTimeNow() - storedInitialTime) where stored initial time is the saved value from when it was created

2 Likes

getservertimenow isn’t on a per-server basis? Wouldn’t os.time() be better? I’ve never used getservertime now so I am unfamiliar with it

1 Like

getservertimenow returns the epoch time on the server, and it’s the most accurate way to get the time across everyone.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.