#DataStore not saving after user rejoins

1 messages · Page 1 of 1 (latest)

glad belfry
#
local DataStoreService = game:GetService("DataStoreService")
local moneyDataStore = DataStoreService:GetDataStore("Money")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Parent = leaderstats
    
    money.Value = moneyDataStore:GetAsync(player.UserId) or 0
    print(money.Value)
end)

game.Players.PlayerRemoving:Connect(function(plr)
    print(plr.leaderstats.Money.Value)
    moneyDataStore:SetAsync(plr.UserId, plr.leaderstats.Money.Value)
end)```
serene moon
#

maybe bindtoclose()?

#

the whole server shuts down in roblox studio when u leave

#

unless your team testing

#

so thats why bindtoclose runs a few more moments before closing

strange kayak
#

yeah but make sure u check if its studio before running bindtoclose

stoic carbon
#

try using pcalls bro

#

and make sure u got data store access permission in the game

serene moon
#

well this basic one should pretty much work even if slight chance of failing

bitter salmonBOT
#

studio** You are now Level 17! **studio

stoic carbon
#

maybe he has data store access off?

serene moon
#

its either he hasnt enabled access or bindtoclose() if he is using roblox studio to test his stuff that is

stoic carbon
#

its good to have bindtoclose() for real games just incase the servers crash or shutdown

#

he is learning

serene moon
#

well if u leave, the servers shut down too inside roblox studio since it is a solo play

stoic carbon
bitter salmonBOT
#

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

serene moon
#

it doesnt for me

#

so i need to use bindtoclose

stoic carbon
#

idk wth is with ur games

#

whatever

long lark
#

use profilestore

stoic carbon
long lark
#

profilestore is simple lmao

serene moon
long lark
#

ur dumb if u cant understand it

serene moon
#

basics first

stoic carbon
#

does he even know abt them thats the thing

long lark
#

profilestore easier than regular datastores 💀

stoic carbon
long lark
#

i learned profilestore before datastores

#

but whatever

stoic carbon
long lark
#

no

shadow rampart
#

i still dont understand normal datastore methods so i just use profileservice