I'm trying to make this data store save. Before we start I want to say a few things, one, I have api services on, and I'm trying to do this in 2 different scripts.
This is the script that holds the data store:
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("TimeSave")
local badgeservice = game:GetService("BadgeService")
local badgeid = 2124575491
local badgeid2 = 2124565356
local badgeid3 = 2124565358
local badgeid4 = 2124565361
game.Players.PlayerAdded:Connect(function(plr)
local m = 0
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
local gems = Instance.new("IntValue")
gems.Parent = leaderstats
gems.Name = "Time"
local data
local success, err = pcall(function()
data = ds1:GetAsync(plr.UserId)
end)
if success then
gems.Value = data
end
repeat wait()
m = m + 1
if m == 2 then
m = 0
if plr.leaderstats.Time.Value >= 600 then
badgeservice:AwardBadge(plr.UserId, badgeid)
if plr.leaderstats.Time.Value >= 3600 then
badgeservice:AwardBadge(plr.UserId, badgeid2)
if plr.leaderstats.Time.Value >= 18000 then
badgeservice:AwardBadge(plr.UserId, badgeid3)
if plr.leaderstats.Time.Value >= 36000 then
badgeservice:AwardBadge(plr.UserId, badgeid4)
end
end
end
end
end
wait(1)
plr.leaderstats.Time.Value = plr.leaderstats.Time.Value + 1
until plr == nil
end)
I'm trying to make it save in another script for the simplicity of it. Here is the second script that's supposed to make the other script save:
game.Players.PlayerRemoving:Connect(function(Player)
local leaderstats = Player.leaderstats
local timevalue = leaderstats.Time.Value
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("TimeSave")
local success, err = pcall(function()
ds1:SetAsync(Player.UserId, timevalue)
end)
end)
For some reason it won't save, if you know the problem please let me know. Thanks.
