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:
-- December 6, 2015 -- Settings local ToSave = {"Cash"} -- Variables local Player = script.Parent.Parent.Parent.Parent local Stats = Player:WaitForChild("leaderstats") local Button = script.Parent.Parent.TextButton local Button2 = script.Parent.Parent.TextButton2 local DataStore = game:GetService("DataStoreService"):GetDataStore("GameService") local Debounce = false -- Main script local h = Instance.new("Hint",workspace) h.Text = "Waiting for DataReady." Player:WaitForDataReady() h.Text = "Got DataReady." wait(1) function Load() for i = 1,#ToSave do wait(0.1) h.Text = "Loading "..ToSave[1]:lower().."." wait(1) if DataStore:GetAsync(ToSave[1]..Player.userId) then Stats:FindFirstChild(ToSave[1]).Value = DataStore:GetAsync(ToSave[1]..Player.userId) end h.Text = "Loaded "..ToSave[1]:lower().."." end Debounce = false end function Save() for i = 1,#ToSave do wait(0.1) h.Text = "Saving "..ToSave[1]:lower().."." wait(1) DataStore:SetAsync(ToSave[1]..Player.userId,Stats:FindFirstChild(ToSave[1]).Value) h.Text = "Saved "..ToSave[1]:lower().."." print("Successfully saved "..ToSave[1]) table.remove(ToSave,1) end ToSave = {"Cash"} Debounce = false end Button.MouseButton1Click:connect(function() if not Debounce then Debounce = true Save() end end) Button2.MouseButton1Click:connect(function() if not Debounce then Debounce = true Load() end end)