I am trying to get it to save seconds, and later on Hours and minutes. but it keeps saying API Services rejected request with error. HTTP 403 (Forbidden)
datastoreservice = game:GetService("DataStoreService")
datastore = datastoreservice:GetDataStore("TimeSaving")
game.Players.PlayerAdded:Connect(function(player)
local timer = script.Time:Clone()
timer.Parent = player
local data
local success,errormessage = pcall(function()
local data = datastore:GetAsync(player.UserId.."-TimePlayed")
end)
if success then
timer.Seconds.Value = data
else
print("Error loading data")
warn(errormessage)
end
while true do
wait(1)
timer.Seconds.Value = timer.Seconds.Value + 1
if timer.Seconds.Value == 60 then
timer.Seconds.Value = 0
timer.Minutes.Value = timer.Minutes.Value + 1
end
if timer.Minutes.Value == 60 then
timer.Minutes.Value = 0
timer.Hours.Value = timer.Hours.Value + 1
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success,errormessage = pcall(function()
local seconds = player.Time.Seconds.Value
local minutes = player.Time.Minutes.Value
local hours = player.Time.Hours.Value
datastore:SetAsync(player.UserId.."-TimePlayed",seconds)
end)
if success then
print("Player data saves")
else
print("Issue saving data")
warn(errormessage)
end
end)

2 comments
API services is on, but the game is owned by a group.
Only the owner of the TC can make DataStore requests then.