#datastore issues
75 messages · Page 1 of 1 (latest)
I think it’s because ur setting a table a fix would be DataTable[1] I think
** You are now Level 1! **
which one
hol up
if i give myself coins and leave it prints the correct amount in the table
but when i join back it says i dont have data
in the LeaderstatsDataStore:SetAsync(player.UserId.."-Leaderstats",DataTable) line?
if so
Yes
No
I am on my phonne rn sorry
you can set tables
Just get back this code and put a bool value named SaveInStudio in server storage set it to true and try again
alr
anything else i have to do with this?
lol
no
didnt work
this print doesnt work
print("player left, saving data for", player)
any erros?
nope
ok instead add into the player added and change it to coins.Changed
this is a server script
and?
yes u do
yeah i see that u said add it to when a player is added
only through certain functions
yes
u could loop through all players, using player removing, use player added
all work
so how would i do this
after you set the coins value you add coins.Changed:Connect(function(newValue)
-- code
end)
When I get home I can fix the issues
You shouldn’t do that
You should only save data when leaving
it depends
Setting player data every single time the value change is bad practice
And it is highly not recommended
Because data stores have limits
Fr

yes but it depends on how often you change your value, playerremoving isnt the best in studio

i use that too
but if you wanted to use playerremoving you would have to use it in game, not in studio
in typical datastores in studio, the data often cannot save in time
in game, it will successfully fire
it works in my other game
i have actually no clue how too
local DataStoreService = game:GetService("DataStoreService")
local LeaderstatsDataStore = DataStoreService:GetDataStore("LeaderstatsDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats" --creating leaderstats
leaderstats.Parent = player
local Diamonds = Instance.new("IntValue")
Diamonds.Name = "Diamonds" --creating diamonds in leadertstats
Diamonds.Parent = leaderstats
local coins = Instance.new("IntValue") --creating coins
coins.Name = "Coins"
coins.Parent = player
local data = LeaderstatsDataStore:GetAsync(player.UserId.."-Leaderstats") --data
if data == nil then
local Coins = player.Coins
Diamonds.Value = 0
Coins.Value = 0
else
local Coins = player.Coins
Diamonds.Value = data["Diamonds"]
Coins.Value = data["Coins"]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Diamonds = player.leaderstats.Diamonds.Value
local Coins = player.Coins.Value
local DataTable = {
["Diamonds"] = Diamonds,
["Coins"] = Coins}
LeaderstatsDataStore:SetAsync(player.UserId.."-Leaderstats",DataTable)
end)
print("Leaderstats completed + data store!")
this works entirely
try in game
legit just copy paste this code
you have .Connect?
i did
but removed the diamonds
hol up i gotta add a way to get coins in game so i can test in game