No matter what code I use, my own, or from someone else, the data never saves. I have tried about 6 or 7 maybe 8 different datastores fro youtube videos and toolbox... I even attempted myself but it never works, I have access to studio API on I have tried in studio and the real game, but it never saves. Can anyone help?
Heres my leaderboard script that 100 percent works (change exp and kills to whatever name you want)
local DS = game:GetService("DataStoreService") local ExpStore = DS:GetOrderedDataStore("Exp") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local exp = Instance.new("IntValue", leaderstats) exp.Name = "Exp" pcall(function() local ExpVal = ExpStore:GetAsync(player.UserId) if ExpVal then exp.Value = ExpVal end end) game.ServerStorage.GiveExp.Event:Connect(function(amount,plr) if player.Name == plr.Name then exp.Value = exp.Value + amount end end) end) game.Players.PlayerRemoving:Connect(function(player) pcall(function() if player:WaitForChild("leaderstats") and player.leaderstats:WaitForChild("Exp") and player.leaderstats.Exp.Value > 0 then ExpStore:SetAsync(player.UserId, player.leaderstats.Exp.Value) end end) end) --------------------------------------------------------------- local Ds = game:GetService("DataStoreService") local KillsStore = Ds:GetOrderedDataStore("Kills") game.Players.PlayerAdded:Connect(function(player) local leaderstats = player:WaitForChild("leaderstats") leaderstats.Name = "leaderstats" local Kills = Instance.new("IntValue", leaderstats) Kills.Name = "Kills" Kills.Parent = leaderstats pcall(function() local KillsVal = KillsStore:GetAsync(player.UserId) if KillsVal then Kills.Value = KillsVal end end) game.ServerStorage.GiveKills.Event:Connect(function(amount,plr) if player.Name == plr.Name then Kills.Value = Kills.Value + amount end end) end) game.Players.PlayerRemoving:Connect(function(player) pcall(function() if player:WaitForChild("leaderstats") and player.leaderstats:WaitForChild("Kills") and player.leaderstats.Kills.Value > 0 then KillsStore:SetAsync(player.UserId, player.leaderstats.Kills.Value) end end) end) -------------------------------------------------------- local Ds = game:GetService("DataStoreService") local SwordBuxStore = Ds:GetOrderedDataStore("SwordBux") game.Players.PlayerAdded:Connect(function(player) local leaderstats = player:WaitForChild("leaderstats") leaderstats.Name = "leaderstats" local SwordBux = Instance.new("IntValue", leaderstats) SwordBux.Name = "SwordBux" SwordBux.Parent = leaderstats pcall(function() local SwordBuxVal = SwordBuxStore:GetAsync(player.UserId) if SwordBuxVal then SwordBux.Value = SwordBuxVal end end) game.ServerStorage.GiveSwordBux.Event:Connect(function(amount,plr) if player.Name == plr.Name then SwordBux.Value = SwordBux.Value + amount end end) end) game.Players.PlayerRemoving:Connect(function(player) pcall(function() if player:WaitForChild("leaderstats") and player.leaderstats:WaitForChild("SwordBux") and player.leaderstats.SwordBux.Value > 0 then SwordBuxStore:SetAsync(player.UserId, player.leaderstats.SwordBux.Value) end end) end)
PUT THIS IN SERVERSCRIPTSERVICE