I need to save leaderstats in DataStore. My leaderstats are:
Cash
InBucket
Catches
I need a universal but simple script for saving these, and also other values I didn't mention. I know there ARE TONS of tutorials and guides for it but seems like none helped me yet (out of date or too complex). Also, I already have these values created in a script, and I want to save in another, so please do not make them again. (IK it isn't a request site, if you are against requesters, try to at least explain.) Please help... Any help is much appreciated. Also, I deleted the script cause it didn't work, if you could explain me how to create new simple one, i would really appreciate it :)
Ok I wrote this script for you that should save the stats. If you have any errors dm me and I will try to fix them. You could also look at the wiki for later stuff, for example DataStore in this case https://developer.roblox.com/api-reference/function/DataStoreService/GetDataStore .
01 | local DataStore = game:GetService( "DataStoreService" ) |
02 | local Http = game:GetService( "HttpService" ) |
03 | local Stats = DataStore:GetDataStore( "Stats" ) |
04 |
05 | function GetStats(Player) |
06 | local Success,Return = pcall ( function () |
07 | return Stats:GetAsync(Player.UserId) |
08 | end ) |
09 | if Success then |
10 | Return = Http:JSONDecode(Return) |
11 | return Return |
12 | else |
13 | print ( "Getting data error :" ..Return) |
14 | return { } |
15 | end |