Is there anyway I can make this DataStore script shorter/more organized?
Before I saw someone on this site say to use Table
's when you plan on storing ton's of stuff in DataStore, so I tried doing it for testing purposes and came out with this, it work's fine, but I was wondering if there is anyway I can make this script shorter/make it more organized.
Any help appreciated.
It is GUI based, but I converted it to hint's for ScriptingHelpers.
Script:
04 | local ToSave = { "Cash" } |
07 | local Player = script.Parent.Parent.Parent.Parent |
08 | local Stats = Player:WaitForChild( "leaderstats" ) |
10 | local Button = script.Parent.Parent.TextButton |
11 | local Button 2 = script.Parent.Parent.TextButton 2 |
13 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "GameService" ) |
18 | local h = Instance.new( "Hint" ,workspace) |
19 | h.Text = "Waiting for DataReady." |
21 | Player:WaitForDataReady() |
23 | h.Text = "Got DataReady." |
30 | h.Text = "Loading " ..ToSave [ 1 ] :lower().. "." |
32 | if DataStore:GetAsync(ToSave [ 1 ] ..Player.userId) then |
33 | Stats:FindFirstChild(ToSave [ 1 ] ).Value = DataStore:GetAsync(ToSave [ 1 ] ..Player.userId) |
35 | h.Text = "Loaded " ..ToSave [ 1 ] :lower().. "." |
43 | h.Text = "Saving " ..ToSave [ 1 ] :lower().. "." |
45 | DataStore:SetAsync(ToSave [ 1 ] ..Player.userId,Stats:FindFirstChild(ToSave [ 1 ] ).Value) |
46 | h.Text = "Saved " ..ToSave [ 1 ] :lower().. "." |
47 | print ( "Successfully saved " ..ToSave [ 1 ] ) |
48 | table.remove(ToSave, 1 ) |
54 | Button.MouseButton 1 Click:connect( function () |
61 | Button 2. MouseButton 1 Click:connect( function () |