Hello, totday i tried to make a game with an currency that autosaves but it didn’t work.
I looked to the Youtube video from AlvinBlox that’s named Roblox DataStore Tutorial Data Stores & Saving Data Scripting Tutorial. I put the script under this text and I rereaded it to much but i can’t find a mistake.
can the script maybe be outdated?
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-cash")
end)
if success then
cash.Value = data
else
print("There was an error whilst getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:GetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error when saving data")
warn(errormessage)
end
end)
Like whale said, it’s not best to test it in studio since when you click the stop/leave button then the studio session will automatically close without saving any data
Yup, I tried your exact script and it didn’t work. It may be dated like you said. Try this tutorial by TheDevKing instead, I’ve used this tutorial before and it works: