Datastore Troubles: UpdateAsync or SetAsync?
So, I'm having troubles creating keys (multiple keys for the object being requested to be pruchased) to the User's ID, I've done something similar to this before but used a boolean value as the key then upon leaving saved it if it changed and used:
, instead I want to store the value inside the script so it's theoretically impossible to change it without using a script. Currently I have a table value called "Cash" this value is stored in a script so it can't be changed, when the player clicks the button (Event Trigger-er) they fire a BindableEvent
created inside their Player to request the leaderboard to calculate if they can buy this thing. However, they can still buy it again if they have enough money even though they just unlocked it, what I want is to check the datastore to see if the key for the object is true if so, don't fire the event, the reason for it is because again, a player can change a boolean's value easily. Any help is appreciated, if more code is needed I can provide it, also, I don't really expect a giant mass of code, so if you don't want to create it you don't have to, I'm good with an explanation.
Leaderboard:
01 | moneye.Event:connect( function (cost, plr, key) |
02 | if cost < = playerLeaderstats [ plr ] [ "Cash" ] then |
03 | playerLeaderstats [ plr ] [ "Cash" ] = playerLeaderstats [ plr ] [ "Cash" ] - cost |
04 | cashe:Fire(playerLeaderstats [ plr ] [ "Cash" ] ) |
05 | local user = "User_" .. plr.userId |
06 | local saves = Characters:GetAsync(user) |
07 | Characters:UpdateAsync(saves [ 1 ] , function (oldval) |
11 | print (saves [ 1 ] , "leaderboard update ???" ) |
14 | return print ( "Not Enough" ) |
Button/Event Trigger-er:
01 | script.Parent.MouseButton 1 Click:connect( function () |
02 | if saves [ 1 ] = = false then |
03 | local tofire = plr:FindFirstChild( "Events" ).MoneyTransfer |
04 | tofire:Fire(COST, plr, saves [ 1 ] ) |
08 | print (saves [ 1 ] , "< true?" ) |
Datastore Join:
03 | local DataStoreService = game:GetService( 'DataStoreService' ) |
04 | local Characters = DataStoreService:GetDataStore( 'CharacterSaves' ) |
06 | game.Players.PlayerAdded:connect( function (player) |
07 | local user = "User_" .. player.userId |
08 | local saves = Characters:GetAsync(user) |
34 | local Chars = { Char 1 v, Char 2 v, Char 3 v, Char 4 v, Char 5 v, Char 6 v, Char 7 v } |
36 | Characters:SetAsync(user, Chars) |
Datastore Leave:
01 | local DataStoreService = game:GetService( 'DataStoreService' ) |
02 | local Characters = DataStoreService:GetDataStore( 'CharacterSaves' ) |
04 | game.Players.PlayerRemoving:connect( function (player) |
05 | local user = "User_" .. player.userId |
06 | local saves = Characters:GetAsync(user) |
17 | local Chars = { Char 1 , Char 2 , Char 3 , Char 4 , Char 5 , Char 6 , Char 7 } |
19 | Characters:SetAsync(user, Chars) |
Anything else needed let me know.