local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MyTest")
------------------get the dataStore service and name ^^^ -----------------------
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Money"
cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = DataStore:GetAsync(player.UserId.."-Money")
end)
if success then
cash.Value = data
print("wow its working")
else
print("Ur datastore not working buddy")
warn(errormessage.."Ur bad kid")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
DataStore:GetAsync(plr.UserId.."-Money", plr.leaderstats.Money)
end)
if success then
print("it saved bucko")
else
print("ur still bad")
warn(errormessage.."keep urself safe bud :D")
end
end)
help, when i get money it works, but when i leave it doesn’t save
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MyTest")
------------------get the dataStore service and name ^^^ -----------------------
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Money"
cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = DataStore:GetAsync(player.UserId.."-Money")
end)
if success then
cash.Value = data
print("wow its working")
else
print("Ur datastore not working buddy")
warn(errormessage.."Ur bad kid")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
DataStore:SetAsync(plr.UserId.."-Money", plr.leaderstats.Money.Value)
end)
if success then
print("it saved bucko")
else
print("ur still bad")
warn(errormessage.."keep urself safe bud :D")
end
end)