I'm trying to make a button where it exchanges the players 100 Money for 1 Level. The error is Callbacks cannot yield USING DATASTORE If someone could give me advice I would appreciate it!
local LevelStore = game:GetService("DataStoreService"):GetDataStore("LevelStorageNEW")
local MoneyStore = game:GetService("DataStoreService"):GetDataStore("MoneyStorageNEW")
local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local key = "user_" .. Player.userId
local key2 = "user_" .. Player.userId
MoneyStore:UpdateAsync(key, function(oldValue)
local newValue = oldValue or 0
newValue = newValue - 100
LevelStore:UpdateAsync(key2, function(oldValue2)
local newValue2 = oldValue2 or 0
newValue2 = newValue2 + 1
return newValue
end)
end)
end)
