I am making a datastore that stores a table of mutiple values. I have the player leave with the current values and I get no error. When I enter back in the game I get the default values I set. The only value that saves is the totaltime value which tracks the amount of seconds the player spent in the game ever since thet first joined. I still get no error at all. PS: I enabled API studio access btw.
--Get The Service's
local replicatedStorage = game:GetService("ReplicatedStorage")
local httpsService = game:GetService("HttpService")
local dsService = game:GetService("DataStoreService")
local mainStore = dsService:GetDataStore("MainDataStore")
--create player data
game:GetService("Players").PlayerAdded:Connect(function(plr)
--create folders
local leader = Instance.new("Folder",plr)
leader.Name = "leaderstats"
local achievementsFolder = Instance.new("Folder",leader)
achievementsFolder.Name = "Achievements"
local gameplayStats = Instance.new("Folder",leader)
gameplayStats.Name = "GameplayStats"
local playerStats = Instance.new("Folder",leader)
playerStats.Name = "PlayerStats"
--create achievements Values
CompletedTutorial = Instance.new("BoolValue",achievementsFolder)
CompletedTutorial.Name = "CompletedTutorialAchievement"
CompletedTutorial.Value = false
--create gameplay values
CompletedMissions = Instance.new("IntValue",gameplayStats)
CompletedMissions.Name = "CompletedMissions"
CompletedMissions.Value = 0
FailedMissions = Instance.new("IntValue",gameplayStats)
FailedMissions.Name = "FailedMissions"
FailedMissions.Value = 0
PreviousMission = Instance.new("StringValue",gameplayStats)
PreviousMission.Name = "PreviousMission"
PreviousMission.Value = "No Missions Attempted"
TimesDied = Instance.new("IntValue",gameplayStats)
TimesDied.Name = "TimesDied"
TimesDied.Value = 0
TrapsAvoided = Instance.new("IntValue",gameplayStats)
TrapsAvoided.Name = "TrapsAvoided"
TrapsAvoided.Value = 0
TrapsFailed = Instance.new("IntValue",gameplayStats)
TrapsFailed.Name = "TrapsFailed"
TrapsFailed.Value = 0
--create player values
Coins = Instance.new("IntValue",playerStats)
Coins.Name = "Coins"
Coins.Value = 0
local currentDay = os.date("*t").day
local currentMonth = os.date("*t").month
local currentYear = os.date("*t").year
local dateJoined = (currentDay.."/"..currentMonth.."/"..currentYear)
DateFirstJoined = Instance.new("StringValue",playerStats)
DateFirstJoined.Name = "DateFirstJoined"
DateFirstJoined.Value = dateJoined
Rank = Instance.new("StringValue",playerStats)
Rank.Name = "Rank"
Rank.Value = "Junior Assistant"
totalTime = Instance.new("IntValue",playerStats)
totalTime.Name = "TotalTimePlayed"
totalTime.Value = 0
timePlayed = Instance.new("IntValue",playerStats)
timePlayed.Name = "TimePlayed"
timePlayed.Value = 0
Experience = Instance.new("IntValue",playerStats)
Experience.Name = "Experience"
Experience.Value = 0
wait(1)
--load the data
local success, err = pcall(function()
local data = mainStore:GetAsync(plr.UserId)
if data then
--gameplay values
CompletedMissions.Value = data[1]
FailedMissions.Value = data[2]
PreviousMission.Value = data[3]
TimesDied.Value = data[4]
TrapsAvoided.Value = data[5]
TrapsFailed.Value = data[6]
--player stats value
Coins.Value = data[7]
DateFirstJoined.Value = data[8]
Rank.Value = data[9]
totalTime.Value = data[10]
Experience.Value = data[11]
print(CompletedMissions.Value, FailedMissions.Value, PreviousMission.Value, TimesDied.Value, TrapsAvoided.Value, TrapsFailed.Value, Coins.Value, DateFirstJoined.Value, Rank.Value, totalTime.Value, Experience.Value)
else
print("no data")
end
end)
if err then
print("error loading data")
end
end)
--Increment Time Values
incrementor = coroutine.create(function()
while wait(1) do
timePlayed.Value = timePlayed.Value + 1
totalTime.Value = totalTime.Value + 1
end
end)
coroutine.resume(incrementor)
game:GetService("Players").PlayerRemoving:Connect(function(player)
local DataToSave = {CompletedMissions.Value, FailedMissions.Value, PreviousMission.Value, TimesDied.Value, TrapsAvoided.Value, TrapsFailed.Value,
Coins.Value, DateFirstJoined.Value, Rank.Value, totalTime.Value, Experience.Value}
local success, err = pcall(function()
mainStore:SetAsync(player.UserId,DataToSave)
end)
if err then
print("error saving")
end
end)

1 comment
bump