I made a DataStore Service with 2 lstats (Leaderstats) and it worked, but I tried adding 2 more (4) and then it broke. Any ideas?
local dataStores = game:GetService("DataStoreService") local ds1 = dataStores:GetDataStore("CashDataStore") local ds2 = dataStores:GetDataStore("LevelDataStore") local ds3 = dataStores:GetDataStore("RankDataStore") local ds4 = dataStores:GetDataStore("Total XP") local defaultCash = 0 local playersLeft = 0 local defaultLevel = 1 local defaultRank = "InK" local DefaultXP = 0 --[[ Ok So LStats Are Cash Level Rank XP --]] game.Players.PlayerAdded:Connect(function(player) playersLeft = playersLeft + 1 local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Cash = Instance.new("IntValue") Cash.Name = "Cash" Cash.Value = 0 Cash.Parent = leaderstats local Level = Instance.new("IntValue") Level.Name = "Level" Level.Value = 1 Level.Parent = leaderstats local Rank = Instance.new("StringValue") Rank.Name = "Rank" Rank.Value = "Innocent Killer" Rank.Parent = leaderstats local XP = Instance.new("IntValue") XP.Name = "XP" XP.Value = 0 XP.Parent = leaderstats player.CharacterAdded:Connect(function(character) character.Humanoid.Died:Connect(function(character) --Whenever Somebody dies, this event will run if character.Humanoid and character.Humanoid:FindFistChild("creator") then game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name end if character:FindFirstChild("GameTag") then character.GameTag:Destroy() end player.LoadCharacter() end) end) --[[ DATASTORE PLEASE HELP HERE DATASTORE PLEASE HELP HERE DATASTORE PLEASE HELP HERE DATASTORE PLEASE HELP HERE DATASTORE PLEASE HELP HERE ]] local player_data local player_data2 local player_data3 local player_data4 pcall(function() player_data = ds1:GetAsync(player.UserId.."-Cash") -- 1736284-Cash player_data2 = ds2:GetAsync(player.UserId.."-Level") --1736284 Levels player_data3 = ds3:GetAsync(player.UserId.."-Rank") player_data4 = ds4:GetAsync(player.UserId.."-XP") end) if player_data ~= nil then --Player has saved data , load it in Cash.Value = player_data else --New Player Cash.Value = defaultCash end if player_data2 ~= nil then Level.Value = player_data2 else Level.Value = defaultLevel end if player_data3 ~= nil then Rank.Value = player_data3 else Rank.Value = defaultRank end if player_data4 ~= nil then XP.Value = player_data4 else XP.Value = DefaultXP end end) local bindableEvent = Instance.new("BindableEvent") game.Players.PlayerRemoving:Connect(function(player) pcall(function() ds1:SetAsync(player.UserId.."-Cash", player.leaderstats.Cash.Value) ds2:SetAsync(player.UserId.."-Level", player.leaderstats.Level.Value) ds3:SetAsync(player.UserId.."-Rank", player.leaderstats.Rank.Value) ds4:SetAsync(player.UserId.."-XP", player.leaderstats.XP.Value) print('All ds saved') playersLeft = playersLeft - 1 bindableEvent:Fire() end) end) game:BindToClose(function() --This will be triggered upon shutdown while playersLeft > 0 do bindableEvent.Event:Wait() end end)
The problem is probally that you are setting the XP and Rank to a saved value, when there most likely is none, try this, might be something else
local dataStores = game:GetService("DataStoreService") local ds1 = dataStores:GetDataStore("CashDataStore") local ds2 = dataStores:GetDataStore("LevelDataStore") local ds3 = dataStores:GetDataStore("RankDataStore") local ds4 = dataStores:GetDataStore("Total XP") local defaultCash = 0 local playersLeft = 0 local defaultLevel = 1 local defaultRank = "InK" local DefaultXP = 0 --[[ Ok So LStats Are Cash Level Rank XP --]] game.Players.PlayerAdded:Connect(function(player) playersLeft = playersLeft + 1 local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Cash = Instance.new("IntValue") Cash.Name = "Cash" Cash.Value = 0 Cash.Parent = leaderstats local Level = Instance.new("IntValue") Level.Name = "Level" Level.Value = 1 Level.Parent = leaderstats local Rank = Instance.new("StringValue") Rank.Name = "Rank" Rank.Value = "Innocent Killer" Rank.Parent = leaderstats local XP = Instance.new("IntValue") XP.Name = "XP" XP.Value = 0 XP.Parent = leaderstats player.CharacterAdded:Connect(function(character) character.Humanoid.Died:Connect(function(character) --Whenever Somebody dies, this event will run if character.Humanoid and character.Humanoid:FindFistChild("creator") then game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name end if character:FindFirstChild("GameTag") then character.GameTag:Destroy() end player.LoadCharacter() end) end) --[[ DATASTORE PLEASE HELP HERE DATASTORE PLEASE HELP HERE DATASTORE PLEASE HELP HERE DATASTORE PLEASE HELP HERE DATASTORE PLEASE HELP HERE ]] local player_data local player_data2 local player_data3 local player_data4 pcall(function() player_data = ds1:GetAsync(player.UserId.."-Cash") or defaultCash-- 1736284-Cash player_data2 = ds2:GetAsync(player.UserId.."-Level") or defaultLevel--1736284 Levels player_data3 = ds3:GetAsync(player.UserId.."-Rank") or defaultRank player_data4 = ds4:GetAsync(player.UserId.."-XP") or DefaultXP end) if player_data ~= nil then --Player has saved data , load it in Cash.Value = player_data else --New Player Cash.Value = defaultCash end if player_data2 ~= nil then Level.Value = player_data2 else Level.Value = defaultLevel end if player_data3 ~= nil then Rank.Value = player_data3 else Rank.Value = defaultRank end if player_data4 ~= nil then XP.Value = player_data4 else XP.Value = DefaultXP end end) local bindableEvent = Instance.new("BindableEvent") game.Players.PlayerRemoving:Connect(function(player) pcall(function() ds1:SetAsync(player.UserId.."-Cash", player.leaderstats.Cash.Value) ds2:SetAsync(player.UserId.."-Level", player.leaderstats.Level.Value) ds3:SetAsync(player.UserId.."-Rank", player.leaderstats.Rank.Value) ds4:SetAsync(player.UserId.."-XP", player.leaderstats.XP.Value) print('All ds saved') playersLeft = playersLeft - 1 bindableEvent:Fire() end) end) game:BindToClose(function() --This will be triggered upon shutdown while playersLeft > 0 do bindableEvent.Event:Wait() end end)
Hopes this helps