Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Thank you for taking my Datastore Model.
- I've organized the Script for you. All you need to do is either Add, Remove or change the Stats and Datastore Name.
- There is no Virus nor any Credits to me in this so feel free to do whatever to this Script.
- You may also remove the Comments.
- Thank you again.
- Snoopy1333.
- ]]
- --// Services
- local ds = game:GetService("DataStoreService"):GetDataStore("DataName") -- Replace "DataName" with your Data store name you want.
- local StatsToAdd = { -- Add or remove stats, You can also set the default start value too.
- ["Cash"] = 100,
- ["Gems"] = 25,
- }
- --// Functions
- game.Players.PlayerAdded:Connect(function(plr)
- local Prefix = plr.UserId
- local leaderstats = Instance.new("Folder", plr)
- leaderstats.Name = "leaderstats"
- for i,v in pairs(StatsToAdd) do -- This will automate the Table for us so we don't need to use Instance alot and changing Values.
- local NewInst = Instance.new("IntValue", leaderstats) -- 2nd Parameter is the Parent of the instance.
- NewInst.Name = i
- NewInst.Value = v
- end
- local Data = nil
- pcall(function()
- Data = ds:GetAsync(Prefix)
- end)
- if Data ~= nil then
- for i,v in pairs(leaderstats:GetChildren()) do
- v.Value = Data[v.Name]
- end
- end
- end)
- game.Players.PlayerRemoving:Connect(function(plr)
- local Prefix = plr.UserId
- local leaderstats = plr.leaderstats
- pcall(function()
- if leaderstats then
- local SaveData = {}
- for i,v in pairs(leaderstats:GetChildren()) do
- SaveData[v.Name] = v.Value
- end
- ds:SetAsync(Prefix, SaveData)
- end
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment