local AllowStudioDS = true
local DataStoreName = "Player_Data"
local DataStoreServices = game:GetService("DataStoreService")
local DataStore = DataStoreServices:GetDataStore(DataStoreName)
local Access = "Key_ "
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local Player_Key = Access..Player.UserId
local leaderstats = Instance.new("Folder") do
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
end
local Money = Instance.new("NumberValue") do
Money.Name = "Money"
Money.Parent = leaderstats
end
local Player_Data
local Success, Fail = pcall(function()
Player_Data = DataStore:GetAsync(Player_Key)
end)
if Player_Data then
Money.Value = Player_Data[1]
else
Money.Value = 25
end
end)
Players.PlayerRemoving:Connect(function(Player)
local Player_Key = Access..Player.UserId
local Folder = Player:FindFirstChild("leaderstats")
if not Folder then
repeat task.wait(.1) Folder = Player:FindFirstChild("leaderstats") until Folder == Player:FindFirstChild("leaderstats")
end
local TableToSave = {Folder.Money.Value}
if not AllowStudioDS then
warn("Saved failed due to Studio Access of Data Store false.")
return
end
DataStore:SetAsync(Player_Key, TableToSave)
print("Saved!")
end)
Saving doesnt work even though it prints save and i dont know whats wrong