I am trying to store values such as coins in a table and then save the table. I have the values constantly being updated and pcall functions. Whenever I run the script I get the default value of coins and the pcall function error.
--Get The Service's
local replicatedStorage = game:GetService("ReplicatedStorage")
local timePlayedValue = replicatedStorage.PlayerStats:WaitForChild("TimePlayedValue")
local totalTimeValue = replicatedStorage.PlayerStats:WaitForChild("TotalTimeValue")
local httpsService = game:GetService("HttpService")
local dsService = game:GetService("DataStoreService")
local mainStore = dsService:GetDataStore("MainDataStore")
--Get The Gameplay Stats
local CompletedMissionsValue = game:GetService("ReplicatedStorage").GamePlayStats:WaitForChild("CompletedMissionsValue")
local FailedMissionsValue = game:GetService("ReplicatedStorage").GamePlayStats:WaitForChild("FailedMissionsValue")
local PreviousMissionValue = game:GetService("ReplicatedStorage").GamePlayStats:WaitForChild("PreviousMissionValue")
local TimesDiedValue = game:GetService("ReplicatedStorage").GamePlayStats:WaitForChild("TimesDiedValue")
local TrapsAvoidedValue = game:GetService("ReplicatedStorage").GamePlayStats:WaitForChild("TrapsAvoidedValue")
local TrapsFailedValue = game:GetService("ReplicatedStorage").GamePlayStats:WaitForChild("TrapsFailedValue")
--Get The PlayerStats
local CoinsValue = replicatedStorage.PlayerStats:WaitForChild("Coins")
local DateFirstJoinedValue = replicatedStorage.PlayerStats:WaitForChild("DateFirstJoinedValue")
local RankValue = replicatedStorage.PlayerStats:WaitForChild("Rank")
local ExperienceValue = replicatedStorage.PlayerStats:WaitForChild("XP")
--Table To Store Data
local AllStatsTable = {CompletedMissionsValue,FailedMissionsValue,PreviousMissionValue,TimesDiedValue,TrapsAvoidedValue,TrapsFailedValue,CoinsValue,
DateFirstJoinedValue,RankValue,ExperienceValue,totalTimeValue}
--Increment Time Values
incrementor = coroutine.create(function()
while wait(1) do
timePlayedValue.Value = timePlayedValue.Value + 1
totalTimeValue.Value = totalTimeValue.Value + 1
end
end)
coroutine.resume(incrementor)
--FIX DATASTORE
game:GetService("Players").PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
mainStore:SetAsync(player.UserId,AllStatsTable)
end)
if err then
print("error saving")
end
end)
game:GetService("Players").PlayerAdded:Connect(function(player)
local success, err = pcall(function()
local data = mainStore:GetAsync(player.UserId)
if data then
print(data[7])
else
print("no data")
end
end)
if err then
print("error saving")
end
end)

4 comments
its blocked and you didn't answer my question
First, get the player with it's key basically like local Key = "KeyHere|"..player.UserId then, you make a table with the values like table = {lol = 20, lol2 = 200} finally, you take the table and data and use DATASTORE NAME:SetAsync(Key, table) to save the data
Sorry about that I didn't know it was blocked
thanks soo much! That fixed it! :)