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)
Lol, the answer is legit on this website luckily, https://scriptinghelpers.org/guides/saving-and-loading-data-with-datastores thisl ink will tell you basically everything you need to know abt DataStore Service and stuff but, make sure to look at the documentation from the Developer Roblox page also. https://developer.roblox.com/en-us/articles/Saving-Player-Data
Closed as Non-Descriptive by hiimgoodpack and WideSteal321
This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.
Why was this question closed?