After i rejoin my game, all my values go 0, please help me.
local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("FruitSimulatorDataStore02")
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder", game.ReplicatedStorage)
stats.Name = plr.Name.."Stats"
local coins = Instance.new("NumberValue",stats)
coins.Name = "Coins"
coins.Value = data:GetAsync(plr.UserId) or 0
local baglvl = Instance.new("NumberValue",stats)
baglvl.Name = "Bag"
baglvl.Value = data:GetAsync(plr.UserId) or 15
local fruits = Instance.new("NumberValue", stats)
fruits.Name = "Fruits Collected"
fruits.Value = data:GetAsync(plr.UserId) or 0
local world2unlocked = Instance.new("NumberValue",stats)
world2unlocked.Name = "W2Unlocked"
world2unlocked.Value = data:GetAsync(plr.UserId) or 0
end)
game.Players.PlayerRemoving:Connect(function(player)
data:SetAsync(player.UserId, game.ReplicatedStorage[player.Name.."Stats"].Coins.Value, game.ReplicatedStorage[player.Name.."Stats"]["Fruits Collected"].Value, game.ReplicatedStorage[player.Name.."Stats"].Bag.Value, game.ReplicatedStorage[player.Name.."Stats"].W2Unlocked.Value)
print("Saved "..player.Name.."'s Stats.")
end)

4 comments
I dont know if this would even work or make it better but try making the values save into a folder that is added into the player when they join containing all of their stats. Im not to good with save scripts so i dont know much about them so this is what i though of>
Because you have placed the folder in game.ReplicatedStorage
@adieking1 The reason is not because it is in the ReplicatedStorage.
@imKlevi FYI the parent argument for Instance.new is deprecated. Just use instance.Parent = Parent