Help saving player data

Okay, I think I accomplished something. Now I want to save using DataStore, but I don’t know where to start. I don’t know much about DataStore.

Here is the script:

local Tip = script.Parent
local startTime = os.time()  -- Armazena o tempo inicial

local function disp__time(_time)
	_time = _time - startTime  -- Subtrai o tempo inicial
	local days = math.floor(_time / 86400)
	local hours = math.floor((_time % 86400) / 3600)
	local minutes = math.floor((_time % 3600) / 60)
	local seconds = math.floor(_time % 60)

	if seconds == 60 then
		seconds = 0
		minutes = minutes + 1
	end

	if minutes == 60 then
		minutes = 0
		hours = hours + 1
	end

	if hours == 24 then
		hours = 0
		days = days + 1
	end

	local formattedTime = string.format("%d Days, %02d Hours, %02d Minutes, %02d Seconds", days, hours, minutes, seconds)

	Tip.Text = "Play Time: " .. formattedTime
end

-- Atualize a cada segundo (ou o intervalo desejado)
while wait(1) do
	disp__time(os.time())  -- Passe o tempo atual como argumento
end

Using the same topic to avoid opening another one******

What I would do is every time the player enters the game, I would save the tick() in a table and when the player leaves I calculate the duration of their play session, add it to the played time data and remove it from the table.

To show days, hours, minutes and seconds you could make a function to calculate and return a string.

1 Like

uh this might be a little too simple for you…

local time = 0 -- use a database/store
while true do
    wait(1)
    time += 1
end

a little simple sry

1 Like

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