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?
My DataStore isn't saving no matter what, anyone have any idea?
1 answer
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
8 comments
well this is inefficient, also, we dont even know what data the OP wants to save...
I was trying to save leaderstats, I'm wondering if the problem was the way i was adding value.
did u try to make a datastore service
What do you mean by that?
if you want to save leaderstats you have to make a datastore and name it. If you already did this you need to activate it. You can do this by making a Playerremoved function
I'm a bit lost... Do you mean the variable at the beginning? I haven't done datastores before so I'm a bit confused.
so you can use a new int value when the player joins and put that int value into a folder by parenting it to the folder then you have to get the data store service and get a datastore and name it. then you use playerremoved function and tell it to save that folder when the player leaves. IF I WAS CONFUSING YOU CAN TELL ME AND I WILL SHOW YOU THE DATASTORE SCRIPT BC THIS IS HARD TO EXPLAIN
Yeah... This is a tad bit confusing, I'd like it if you were to show me.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
I dunno about you but this video from AlvinBlox worked for me... https://www.youtube.com/watch?v=DkYupSBUpes
please show your script
please show your script
look at my answer