there is the one datastore and it uses dictionary to save her
it doesn’t save tho so its worthless to use datastores when you cant actually fix it
i might fix it i cant because i dont know what is broken with my code what is wrong with her
Easiest way you are going to fix this issue is using multiple datastores, this does require extra code but it is easier to manage.
you can just use an easier datastore system like datastore2 you can make tons of seperate datastores there and it will be in one huge table
Please Send me a Screenshot of your Output when the game is running and after you have stopped the game.
I think it has something to do with the end here is my update code and it works
local DataStoreService = game:GetService("DataStoreService")
local store = DataStoreService:GetDataStore("StatsStore")
local Players =game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local data= store:GetAsync(Player.UserId)
local stats = Instance.new('Folder')
stats.Name = 'leaderstats'
stats.Parent = Player
local cash = Instance.new('IntValue')
cash.Name = 'Cash'
cash.Parent = stats
cash.Value = data['Cash'] or 10
local candy = Instance.new('IntValue')
candy.Name = 'Candy'
candy.Value = data['CandyA']
candy.Parent = stats
local multiplier = Instance.new('IntValue')
multiplier.Name = 'Multiplier'
multiplier.Value = 1
multiplier.Parent = Player
local speed = Instance.new('IntValue')
speed.Name = 'Speed'
speed.Value = 1
speed.Parent = Player
local function change()
local t = {
['Cash'] = Player:WaitForChild('leaderstats'):WaitForChild("Cash").Value,
['CandyA'] = Player:WaitForChild('leaderstats'):WaitForChild("Candy").Value
}
store:SetAsync(Player.UserId,t)
end
candy.Changed:Connect(change)
cash.Changed:Connect(change)
end)
Players.PlayerRemoving:Connect(function(Player)
print('PlayerRemoving: ' .. Player.Name)
local t = {
['Cash'] = Player:WaitForChild('leaderstats'):WaitForChild("Cash").Value,
['CandyA'] = Player:WaitForChild('leaderstats'):WaitForChild("Candy").Value
}
print(t)
store:SetAsync(Player.UserId,t)
end)
I’m sorry that it was in Spanish, there was a translation error
Players.PlayerRemoving:Connect(function(Player)
print(1)
print('PlayerRemoving: ' .. Player.Name)
print(2)
local t = {
['Cash'] = Player:WaitForChild('leaderstats'):WaitForChild("Cash").Value,
['CandyA'] = Player:WaitForChild('leaderstats'):WaitForChild("Candy").Value
}
print(3)
print(t)
store:SetAsync(Player.UserId,t)
print(4)
end)
Change it to this and send a screenshot of output when you stop Studio testing
local DSService = game:GetService(“DataStoreService”):GetDataStore(“Data_Name”)
game.Players.PlayerAdded:Connect(function(PLR)
local uniquekey = “id-”…PLR.UserId
local leaderstats = Instance.new(“Model”, PLR)
local savevalue1 = Instance.new(“NumberValue”, leaderstats)
local savevalue2 = Instance.new(“NumberValue”, leaderstats)
savevalue1.Value = 0
savevalue2.Value = 0
leaderstats.Name = “leaderstats”
savevalue1.Name = “Cash”
savevalue2.Name = “Candy”
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue1.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
else
local NumbersForSaving = {savevalue1.Value, savevalue2.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(PLR)
local uniquekey = “id-”…PLR.UserId
local SaveTable = {PLR.leaderstats[“Cash”].Value, --All in 1 table
PLR.leaderstats[“Candy”].Value
}
DSService:SetAsync(uniquekey, SaveTable)
end)
also btw wrap it up in a pcall so it wont break or yield or else face dataloss
So the Datastore is working now? If yes and you fixed it from someones post please mark it solution for people who may view this in the future.
i fixed it myself i marked the post as topic and i have given code