In my game, when you purchase a weapon, the stats are supposed to save using updateasync, though they are not. I am sending arguments from a local script to a server script using a remote event. The contents of my code will be posted below.
Local Script:
button.MouseButton1Down:Connect(function()
local weaponBackpack = script.Parent.Parent.Parent.ScrollingFrame:GetChildren()
local weaponStorage = myWeaps:GetChildren()
local thePrice = script.Parent.Price.Value
local theWeapon = script.Parent.WeapNum.Value
for i = 1, #weaponStorage do
if theWeapon == i then --If theWeapon is at the i value, then that must be the weapon they buy
local weaponStorage = myWeaps:GetChildren() --Gets all the WeapOwned values and stores in table
if player.leaderstats.Gold.Value >= thePrice and not weaponStorage[i].Value then --Checks if player doesn't have the weapon, and has enougn gold
player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - thePrice --Subract the gold
local newval = player.leaderstats.Gold.Value
remoteEvent:FireServer(player ,player.UserId, thePrice, newval) --Call SaveGold Script
weaponStorage[i].Value = true --Set weapon to true.
end
end
end
end)
Server Script:
remoteEvent.OnServerEvent:Connect(function(player, id, thePrice, newVal)
print(id)
print(thePrice)
print(player.leaderstats.Gold.Value)
local success, errormessage = pcall(function()
dataStore:UpdateAsync(id..'-gold', newVal)
end)
if success then
print('Player gold saved.')
else
print('Error when saving player gold.')
warn(errormessage)
end
end)

1 comment
Review the documentation to UpdateAsync, you'll see why.