Here's the script
--//Variables//--
local DataStoreService = game:GetService("DataStoreService") -- DataStroeService
local MarketPlaceService = game:GetService("MarketplaceService") -- MarketPlaceService
--DataStores--
local leaderstatsData = DataStoreService:GetDataStore("DataV2") -- CashDataStore
--GameChildren--
local Players = game:GetService("Players") -- Players
local ServerStorage = game:GetService("ServerStorage") -- ServerStorage
local Lighting = game:GetService("Lighting") -- Lighting
--//Events//--
Players.PlayerAdded:connect(function(player) -- playeradded
--Variables
local leaderstats = Instance.new("Folder",player) -- leaderstats
leaderstats.Name = "Stats"
local Cash = Instance.new("NumberValue",leaderstats) -- cash
Cash.Name = "Cash"
Cash.Value = 0
local Rebirths = Instance.new("NumberValue",leaderstats) -- rebirths
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
local Fame = Instance.new("NumberValue",leaderstats)
Fame.Name = "Fame"
Fame.Value = 0
local Fans = Instance.new("NumberValue",leaderstats)
Fans.Name = "Fans"
Fans.Value = 0
local FanDonations = Instance.new("NumberValue",leaderstats)
FanDonations.Name = "FanDonations"
FanDonations.Value = 0
local Sponsors = Instance.new("NumberValue",leaderstats)
Sponsors.Name = "Sponsors"
Sponsors.Value = 1
local PhoneLvl = Instance.new("NumberValue",leaderstats)
PhoneLvl.Name = "PhoneLvl"
PhoneLvl.Value = 1
local RobuxDonated = Instance.new("NumberValue",leaderstats)
RobuxDonated.Name = "RobuxDonated"
RobuxDonated.Value = 0
--Loads leaderstatsData Data
local leaderstatsAsync = leaderstatsData:GetAsync(player.UserId) -- leaderstats data async
if leaderstatsAsync ~= nil then -- if has saved data before
Cash.Value = leaderstatsAsync[1]
Rebirths.Value = leaderstatsAsync[2]
Fame.Value = leaderstatsAsync[3]
Fans.Value = leaderstatsAsync[4]
FanDonations.Value = leaderstatsAsync[5]
Sponsors.Value = leaderstatsAsync[6]
PhoneLvl.Value = leaderstatsAsync[7]
RobuxDonated.Value = leaderstatsAsync[8]
else -- if is new and doesnt have any data
local StuffToSave = {
Cash.Value, Rebirths.Value, Fame.Value,
Fans.Value, FanDonations.Value, Sponsors.Value,
PhoneLvl.Value, RobuxDonated.Value
}
leaderstatsData:SetAsync(player.UserId, StuffToSave)
end
end)
Players.PlayerRemoving:connect(function(player)
local leaderstats = player:WaitForChild("Stats")
local leaderstatsAsync = leaderstatsData:GetAsync(player.UserId)
local StuffToSave = {
leaderstats.Cash.Value, leaderstats.Rebirths.Value, leaderstats.Fame.Value,
leaderstats.Fans.Value, leaderstats.FanDonations, leaderstats.Sponsors.Value,
leaderstats.PhoneLvl.Value, leaderstats.RobuxDonated.Value
}
leaderstatsData:SetAsync(player.UserId, StuffToSave)
end)
