How to make time spent on game, like 1 hour and minutes? I’m quite confused.
My script:
--// Variables, Services and functions
local DataStoreService = game:GetService("DataStoreService")
local TimeData = DataStoreService:GetOrderedDataStore("TimeData")
local Players = game:GetService("Players")
local gameHours = 0
local gameMinutes = 0
local gameSeconds = 0
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local playerName = Instance.new("StringValue")
playerName.Name = "Name"
playerName.Value = player.Name
playerName.Parent = leaderstats
local Teir = Instance.new("StringValue")
Teir.Name = "Teir"
Teir.Value = "o"
Teir.Parent = leaderstats
local timeSpent = Instance.new("StringValue")
timeSpent.Name = "Time"
timeSpent.Value = gameHours..":"..gameSeconds
timeSpent.Parent = leaderstats
local playerData
local sucess, err = pcall(function()
playerData = TimeData:GetAsync(player.UserId.." -Time")
end)
if sucess then
timeSpent.Value = playerData
else
warn("Error saving player data!")
end
end)
Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
TimeData:GetAsync(player.UserIDd.." -Time",player.leaderstats.Time.Value)
end)
if success then
print("Data Saved!")
else
warn("Data not saved!")
end
end)
while true do wait(1)
gameSeconds = gameSeconds + 1
gameMinutes = gameSeconds * 60
gameHours = gameMinutes * 60
timeSpent.Value = gameHours..":"..gameSeconds
end
My time value just prints 36000 and stuff like that, It’s my first time implementing this. Thanks in advance! ![]()