Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Made by EmeraldLimes on 14th of Nov. 2020
- Devforum post on how to use: https://devforum.roblox.com/t/ds2handler-an-easier-simpler-way-to-use-ds2-open-source/869823
- ]]
- local Names,Defaults = {
- },{}
- local DS2Handler = {}
- local DS2 = require(script:WaitForChild("DataStore2"))
- function init()
- for _,combineTable in pairs(Defaults) do
- local key, names = combineTable.combineKey, {}
- for name,default in pairs(combineTable) do
- if (name ~= "combineKey") then
- Defaults[name] = default
- table.insert(names,name)
- end
- end
- DS2.Combine(key,table.unpack(names))
- end
- end
- init()
- function DS2Handler.__call(_,func,DS2Name,plr,...)
- if (not func or not DS2Name or not plr) then warn("["..(script.Name).."]","Invalid arguments") return end
- local args = table.pack(...)
- local dataStore = DS2(DS2Name,plr)
- local success,result = pcall(function()
- if (func == "Get") then
- return dataStore:Get(Defaults[DS2Name])
- elseif (func == "Increment") then
- local incrementValue = table.unpack(args)
- dataStore:Increment(incrementValue,Defaults[DS2Name])
- elseif (func == "Set") then
- local setTo = table.unpack(args)
- dataStore:Set(setTo)
- elseif (func == "GetTable") then
- return dataStore:GetTable(Defaults[DS2Name])
- elseif (func == "OnUpdate") then
- local callback = table.unpack(args)
- dataStore:OnUpdate(callback)
- callback(dataStore:Get(Defaults[DS2Name]))
- end
- end)
- if (success) then
- return result
- else
- warn("[DS2Handler] "..result)
- end
- end
- return setmetatable(DS2Handler,DS2Handler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement