Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Script Variables \\--
- local Players = game:GetService('Players')
- local DataStore = game:GetService('DataStoreService')
- local RunService = game:GetService('RunService')
- local playerData = DataStore:GetDataStore('Gamerν')
- --// Settings \\--
- local StarterData = {
- Skill1 = 'One';
- Skill2 = 'Two';
- Skill3 = 'Three';
- Skill4 = 'Four';
- Skill5 = 'Five';
- Skill6 = 'E';
- Skill7 = 'R';
- Skill8 = 'C';
- Skill9 = 'V';
- Sheathe = 'Q'; --Sheath/Unsheath weapon
- Inventory = 'I'; --Inventory
- Settings = 'O'; --Options/Settings
- Friends = 'U'; --Online friends, and the world they're in
- skillTree = 'K'; --Skill tree
- Sprint = 'LeftControl'; --Sprint
- Block = 'F';
- Trees = true;
- Level = 1
- };
- local savetable = {};
- local AUTO_SAVE_INTERVAL = 180;
- --// Functions \\--
- --/ Load Starter Data \--
- local function loadStarterData(Player)
- local Key = "ν_"..Player.UserId
- local Hotkeys = Instance.new('Folder')
- Hotkeys.Name = "Keybinds"
- Hotkeys.Parent = Player
- local Options = Instance.new('Folder')
- Options.Name = "Options"
- Options.Parent = Player
- local Stats = Instance.new('Folder')
- Stats.Name = "Stats"
- Stats.Parent = Player
- local Inventory = Instance.new('Folder')
- Inventory.Name = "Inventory"
- Inventory.Parent= Player
- for i, v in pairs(StarterData) do
- if typeof(v) == 'string' then
- local strValue = Instance.new('StringValue')
- strValue.Parent = Hotkeys
- strValue.Name = i
- strValue.Value = v
- elseif typeof(v) == 'boolean' then
- local boolValue = Instance.new('BoolValue')
- boolValue.Parent = Options
- boolValue.Name = i
- boolValue.Value = v
- elseif typeof(v) == 'number' then
- local intValue = Instance.new('IntValue')
- intValue.Parent = Stats
- intValue.Name = i
- intValue.Value = v
- end
- end
- print(Player.Name..'\'s data has been created..')
- end
- --/ Load Data \--
- local function loadData(Player)
- local Key = "ν_"..Player.UserId
- local Data
- local success, err = pcall(function()
- Data = playerData:GetAsync(Key)
- end)
- if success then
- print('Lmao this fucking works what how')
- elseif err then
- print('Lmao this was expected')
- end
- if Data then
- for i,v in pairs(Data) do
- if typeof(v) == 'string' then
- Player.Hotkeys[i].Value = v
- elseif typeof(v) == 'boolean' then
- Player.Options[i].Value = v
- elseif typeof(v) == 'number' then
- Player.Stats[i].Value = v
- end
- end
- print(Player.Name..'\'s data has been loaded!')
- else
- print(Player.Name..' has no data. Generated new data!')
- end
- end
- --/ Save Data \--
- local function saveData(Player)
- local Key = "ν_"..Player.UserId
- local Data = {};
- for _, v in pairs(Player.Keybinds:GetChildren()) do
- Data[v.Name] = v.Value
- end
- for _, v in pairs(Player.Keybinds:GetChildren()) do
- Data[v.Name] = v.Value
- end
- for _, v in pairs(Player.Keybinds:GetChildren()) do
- Data[v.Name] = v.Value
- end
- local function UpdateAsyncFunction(oldValue)
- local previousData = oldValue or {DataId = 0}
- if Data.DataId == previousData.DataId then
- Data.DataId = Data.DataId + 1
- return Data
- else
- return nil
- end
- end
- local success,err = pcall(function()
- if playerData == nil then
- playerData:SetAsync(Key, Data)
- print('Set data!')
- else
- playerData:UpdateAsync(Key, UpdateAsyncFunction())
- print('Updated data!')
- end
- end)
- if success then
- print('Lmao this fucking works what how')
- elseif err then
- print('Lmao this was expected')
- end
- end
- Players.PlayerAdded:Connect(function(Player)
- loadStarterData(Player)
- loadData(Player)
- end)
- Players.PlayerRemoving:Connect(function(Player)
- saveData(Player)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement