#datastore issues

75 messages · Page 1 of 1 (latest)

turbid gazelle
#

so what does it print

final vale
#

I think it’s because ur setting a table a fix would be DataTable[1] I think

red creekBOT
#

studio** You are now Level 1! **studio

round briar
#

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

round briar
final vale
#

I am on my phonne rn sorry

turbid gazelle
#

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

round briar
#

alr

round briar
turbid gazelle
round briar
#

this print doesnt work

#

print("player left, saving data for", player)

turbid gazelle
#

any erros?

round briar
turbid gazelle
#

ok instead add into the player added and change it to coins.Changed

round briar
#

this is a server script

turbid gazelle
#

and?

round briar
#

so i have no way to refer to a individual player

#

oh wait nvm

turbid gazelle
#

yes u do

round briar
#

yeah i see that u said add it to when a player is added

round briar
turbid gazelle
#

yes

#

u could loop through all players, using player removing, use player added

#

all work

round briar
turbid gazelle
#

after you set the coins value you add coins.Changed:Connect(function(newValue)
-- code
end)

final vale
#

When I get home I can fix the issues

final vale
#

You should only save data when leaving

turbid gazelle
final vale
#

Setting player data every single time the value change is bad practice

#

And it is highly not recommended

#

Because data stores have limits

turbid gazelle
#

just make it save every tick

final vale
turbid gazelle
turbid gazelle
final vale
round briar
#

while true do

#

lol

final vale
#

While task.wait()

#

Best fr

round briar
#

i use that too

turbid gazelle
#

in typical datastores in studio, the data often cannot save in time

#

in game, it will successfully fire

round briar
#

i have actually no clue how too

turbid gazelle
#

try in game with your old game

round briar
#
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

turbid gazelle
#

try in game

round briar
#

ok

#

what the heck

turbid gazelle
#

legit just copy paste this code

turbid gazelle
round briar
#

i think i just found what was wrong lol

#

nvm but

#

i didnt have a PlayerRemoving

round briar
#

but removed the diamonds

#

hol up i gotta add a way to get coins in game so i can test in game