Hi, First of all I am a new scripter and I was following @Alvin_Blox 's tutorial.
After I finished the game I tested it but surprise surprise, I got a problem with Datastores.
The amount of Cash I have saves, but the weapons that I buy from the shop does not save.
what have I done to try and solve this?
I looked it up but found nothing.
I have read over my scripts countless times
checked the output, (nothing there)
I even sent hours following the tutorial again to make game again on empty baseplate (the same thing happen)
Its not on a group
So I didn’t want to make this post, but I don’t have a choice.
the part of my code that saves the data
-- Data Stores
local player_data
local weaponsData
local equippedData
pcall(function()
player_data = dataStores:GetAsync(player.UserId.."-Coins")
end)
pcall(function()
weaponsData = dataStores:GetAsync(player.UserId.."-Weps")
end)
pcall(function()
equippedData = dataStores:GetAsync(player.UserId.."-EquippedValue")
end)
if player_data ~= nil then
-- Player has saved data, load it in
Coins.Value = player_data
else
-- New player
Coins.Value = defaultCash
end
if weaponsData then
for _, weapon in pairs (weaponsData)do
if game.ServerStorage.Items:FindFirstChild(weapon)then
local weaponClone = game.ServerStorage.Items[weapon]:Clone()
weaponClone.Parent = inventory
print (weapon.." loaded in")
end
end
if equippedData then
equipped.Value = equippedData
player:WaitForChild("PlayerGui")
game.ReplicatedStorage.SendEquipped:FireClient(player,equippedData)
end
else
print("No weapons Data")
end
that’s what I did, I published the game and tested it with an alt but it didn’t work. I checked the console for Errors and I found the one above in the screenshot.
I already tried putting prints in loops, and I keep getting that error in the screenshot.
LoadChatInfoInternal had an error: HTTP 503 (service unavailable)
pcall(function()
dataStores:SetAsync(player.UserId.."-Coins",player.leaderstats.Coins.Value)
end)
pcall(function()
local weapons = game.ServerStorage.PlayerData[player.Name].Inventory:GetChildren()
local weaponsTable = {}
for _, v in pairs (weapons) do
table.insert(weaponsTable,v.Name)
end
dataStores:SetAysnc(player.UserId.."-Weps",weaponsTable)
if game.ServerStorage.PlayerData[player.Name].Equipped.Value ~= nil then
local equippedVal = game.ServerStorage.PlayerData[player.Name].Equipped
dataStores:SetAysnc(player.UserId.."-EquippedValue",equippedVal.Value)
print("worked")
end
end)
print("Saved Weapons and Points")
playersLeft = playersLeft - 1
bindableEvent:Fire()
end)
game:BindToClose(function()
– This will be triggered upon shutdown
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
pcall(function()
dataStores:SetAsync(player.UserId.."-Coins",player.leaderstats.Coins.Value)
end)
pcall(function()
local weapons = game.ServerStorage.PlayerData[player.Name].Inventory:GetChildren()
local weaponsTable = {}
for _, v in pairs (weapons) do
table.insert(weaponsTable,v.Name)
end
print(table.concat(weaponsTable, ', '))
dataStores:SetAysnc(player.UserId.."-Weps",weaponsTable)
if game.ServerStorage.PlayerData[player.Name].Equipped.Value ~= nil then
local equippedVal = game.ServerStorage.PlayerData[player.Name].Equipped
dataStores:SetAysnc(player.UserId.."-EquippedValue",equippedVal.Value)
end
end)