Hello, the names fried and I watched a tutorial video from the DevKing/Tapwater about datastores and I followed the whole video, when it didn’t save I was like ok my fault checked the output nothing, nothing was wrong it just wasn’t saving for some reason help me please, I tried every where, comments, youtube.
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 MoneyBag = Instance.new("IntValue")
MoneyBag.Name = "MoneyBag"
MoneyBag.Parent = leaderstats
local UserId = "Player_"..player.UserId
local data
local sucsess, errormessage = pcall(function()
data = myDataStore:GetAysnc(UserId)
end)
if sucsess then
MoneyBag.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local UserId = "Player_"..player.UserId
local data = player.leaderstats.MoneyBag.Value
local sucsess, errormessage = pcall(function()
myDataStore:SetAsync(UserId, data)
end)
if success then
print("Data Saved Successfully!")
else
if errormessage then
print("Oh NO NO NO NO NO a Mistake Has Been Made")
warn(errormessage)
end
end
end)
no, that’s not what I meant I just wrote it out wrong I’ve been scripting for 5-6 months now, so I have the basic knowledge I am also trying to make the BindToClose()
I doesn’t seem to be working
local ds = game:GetService("DataStoreService"):GetDataStore("--MoneyBag01")
game.Players.PlayerAdded:Connect(function(player)
local key = "moneybag-"..player.userId
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats" --Keep this lowercase
local currency = Instance.new("IntValue",folder)
currency.Name = "MoneyBag" --Just your currency I got from your script, you can change it to whatever
currency.Value = 0 --The starting value for when the player first joins the game
local save = ds:GetAsync(key)
if save then
currency.Value = save --Saving the amount the player got
end
currency.Changed:Connect(function()
ds:SetAsync(key,currency.Value)
end)
end)
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
local BTO = game:BindToClose()
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local MoneyBag = Instance.new("IntValue")
MoneyBag.Name = "MoneyBag"
MoneyBag.Parent = leaderstats
local UserId = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAysnc(UserId)
end)
if success then
MoneyBag.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local UserId = “Player_”…player.UserId
local data = player.leaderstats.MoneyBag.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(UserId, data)
end)
if success then
print("Data Saved Sucessfully!")
else
if errormessage then
print("Oh NO NO NO NO NO a Mistake Has Been Made")
warn(errormessage)
end
end
end)
BTO(function ()
print(2*2) — Not Needed just there to make sure it prints
wait(3)
print(“Done”)
end)
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore") -- Your DataStore Name
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local MoneyBag = Instance.new("NumberValue", leaderstats)
MoneyBag.Name = "MoneyBag"
local data
local IsSaved,DataStoreError = pcall(function()
data = myDataStore:GetAsync(player.UserId) or 0
end)
local function Save(Player,Data) -- // Does a SaveFunction
local CallBack = pcall(function()
myDataStore:SetAsync(Player, Data)
end)
if CallBack then
print('Data Saved')
elseif not CallBack then
error('Data Error '..tostring(CallBack))
end
end
MoneyBag.Changed:Connect(function()
Save(player.UserId, MoneyBag.Value)
end)
game.Players.PlayerRemoving:Connect(function(PlayerWhoLeft)
Save(PlayerWhoLeft.UserId, MoneyBag.Value)
end)
end)