Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is :GetAsync() now working correctly? [SOLVED BECAUSE YOU ALL DIDN'T HELP]

Asked by 5 years ago
Edited 5 years ago

Basically, I have a system that saves the player's data whenever they leave and loads it whenever they join. For some unknown reason, whenever a value is changed from the player's data, it fails to to get the player's data (GetAsync) and it doesn't move on to the next piece of code. This is strange behavior as I have never encountered it before, but this is the first time I'm saving all the player's data into one data store. I'm using a dictionary to save the player's data, and I'm loading their data into folders. Here's a snippet of the code that saves the player's data,

function SaveData(player)
print("Saving Data From "..player.Name)
local PlayerFolder = game.ReplicatedStorage["Player Data"]:FindFirstChild(player.Name.." Data")
local OriginalData = PrimaryData:GetAsync("user_"..player.UserId)
local TableData = HttpService:JSONDecode(OriginalData)
TableData.ClassType = PlayerFolder["Class Type"].Value
TableData.Tier = PlayerFolder["Tier Folder"].Tier.Value
TableData.Level = PlayerFolder["Tier Folder"].Level.Value
TableData.ArmorLevel = PlayerFolder["Armor Level"].Value
TableData.Wins = PlayerFolder.Statistics.Wins.Value
TableData.Losses = PlayerFolder.Statistics.Losses.Value
TableData.Kills = PlayerFolder.Statistics.Kills.Value
TableData.Deaths = PlayerFolder.Statistics.Deaths.Value
TableData.Coins = PlayerFolder.Coins.Value
TableData.Weapons = {}
for i,v in pairs(PlayerFolder["Weapons Folder"]:GetChildren()) do
if v:IsA("StringValue") then
table.insert(TableData.Weapons,v.Value)
end
end
local EncodedData = HttpService:JSONEncode(TableData)
print(EncodedData)
PrimaryData:SetAsync("user_"..player.UserId,EncodedData)
end

If you want to test this out yourself or you need more information, here's my whole piece of code,

--// Created by McRocketNuggets //--
--Variables--
local PlayersService = game:GetService("Players")
local PrimaryData = game:GetService("DataStoreService"):GetDataStore("PrimaryDatav5")
local PrimaryEvent = Instance.new("RemoteEvent",game.ReplicatedStorage)
PrimaryEvent.Name = "Primary Event"
local HttpService = game:GetService("HttpService")
--Functions-- 
function CreateDataFolders(player)
local CurrentData = PrimaryData:GetAsync("user_"..player.UserId)
local TableData = HttpService:JSONDecode(CurrentData)
local PlayerFolder = Instance.new("Folder",game.ReplicatedStorage["Player Data"])
PlayerFolder.Name = player.Name.." Data"
local ClassType = Instance.new("StringValue",PlayerFolder)
ClassType.Value = TableData.ClassType
ClassType.Name = "Class Type"
local TierFolder = Instance.new("Folder",PlayerFolder)
TierFolder.Name = "Tier Folder"
local Tier = Instance.new("StringValue",TierFolder)
Tier.Value = TableData.Tier
Tier.Name = "Tier"
local Level = Instance.new("NumberValue",TierFolder)
Level.Value = TableData.Level
Level.Name = "Level"
local ArmorLevel = Instance.new("NumberValue",PlayerFolder)
ArmorLevel.Value = TableData.ArmorLevel
ArmorLevel.Name = "Armor Level"
local StatsFolder = Instance.new("Folder",PlayerFolder)
StatsFolder.Name = "Statistics"
local Kills = Instance.new("NumberValue",StatsFolder)
Kills.Name = "Kills"
Kills.Value = TableData.Kills
local Deaths = Instance.new("NumberValue",StatsFolder)
Deaths.Name = "Deaths"
Deaths.Value = TableData.Deaths
local Wins = Instance.new("NumberValue",StatsFolder)
Wins.Name = "Wins"
Wins.Value = TableData.Wins
local Losses = Instance.new("NumberValue",StatsFolder)
Losses.Name = "Losses"
Losses.Value = TableData.Losses
local Cash = Instance.new("NumberValue",PlayerFolder)
Cash.Name = "Coins"
Cash.Value = TableData.Coins
local WeaponsFolder = Instance.new("Folder",PlayerFolder)
WeaponsFolder.Name = "Weapons Folder"
for i,v in pairs(TableData.Weapons) do
local visualItem = Instance.new("StringValue",WeaponsFolder)
visualItem.Name = v
visualItem.Value = v
end
end
function SaveData(player)
print("Saving Data From "..player.Name)
local PlayerFolder = game.ReplicatedStorage["Player Data"]:FindFirstChild(player.Name.." Data")
local OriginalData = PrimaryData:GetAsync("user_"..player.UserId)
local TableData = HttpService:JSONDecode(OriginalData)
TableData.ClassType = PlayerFolder["Class Type"].Value
TableData.Tier = PlayerFolder["Tier Folder"].Tier.Value
TableData.Level = PlayerFolder["Tier Folder"].Level.Value
TableData.ArmorLevel = PlayerFolder["Armor Level"].Value
TableData.Wins = PlayerFolder.Statistics.Wins.Value
TableData.Losses = PlayerFolder.Statistics.Losses.Value
TableData.Kills = PlayerFolder.Statistics.Kills.Value
TableData.Deaths = PlayerFolder.Statistics.Deaths.Value
TableData.Coins = PlayerFolder.Coins.Value
TableData.Weapons = {}
for i,v in pairs(PlayerFolder["Weapons Folder"]:GetChildren()) do
if v:IsA("StringValue") then
table.insert(TableData.Weapons,v.Value)
end
end
local EncodedData = HttpService:JSONEncode(TableData)
print(EncodedData)
PrimaryData:SetAsync("user_"..player.UserId,EncodedData)
end
function EventFired(player,topic,body,conclusion,...)
PrimaryEvent:FireClient(player,topic,body,conclusion,...)
end
function EventReceieved(player,topic,body,conclusion)
if topic == "[Insert topic]" then
--code
return
end
end
PrimaryEvent.OnServerEvent:Connect(EventReceieved)
PlayersService.PlayerAdded:Connect(function(player)
local CurrentPlayerData = PrimaryData:GetAsync("user_"..player.UserId)
if CurrentPlayerData == nil then
local Table = {
    ["PlayerId"] = player.UserId;
    ["ClassType"] = "N/A";
    ["Tier"] = "Bronze";
    ["Level"] = 4;
    ["ArmorLevel"] = 1;
    ["Weapons"] = {};
    ["Wins"] = 0;
    ["Losses"] = 0;
    ["Kills"] = 0;
    ["Deaths"] = 0;
    ["Coins"] = 0;
    }
local JSONData = HttpService:JSONEncode(Table)
local NewData = PrimaryData:SetAsync("user_"..player.UserId,JSONData)
CreateDataFolders(player)
else
CreateDataFolders(player)
end
end)
PlayersService.PlayerRemoving:Connect(function(player)
SaveData(player)
end)

Thank you!

2
It would be a great help to yourself and others if you indented your code. It can also help you spot problems before they arise. This is just a note not an answer User#21908 42 — 5y
0
Sorry about that, it's been a habit of mine to format it similar to a novel. McRocketNuggets 65 — 5y

1 answer

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
5 years ago
Edited 5 years ago

Now this is a story all about how My life got flipped turned upside down And I'd like to take a minute, just sit right there I'll tell you how I became the prince of a town called Bel-Air

In West Philadelphia, born and raised On the playground is where I spent most of my days Chillin' out, maxin', relaxin' all cool And all shootin' some b-ball outside of the school When a couple of guys who were up to no good Started makin' trouble in my neighborhood I got in one little fight and my mom got scared And said "You're movin' with your auntie and uncle in Bel-Air"

I whistled for a cab and when it came near The license plate said 'Fresh' and it had dice in the mirror If anything I could say that this cab was rare But I thought "Nah, forget it, yo holmes, to Bel-Air!"

I pulled up to the house about 7 or 8 And I yelled to the cabbie "Yo holmes, smell ya later" Looked at my kingdom, I was finally there To sit on my throne as the Prince of Bel-Air

The issue was resolved and it turned out to be not an issue at all.

Ad

Answer this question