local moneyStore = DS:GetDataStore("Money")
local remote = game:GetService("ReplicatedStorage").CashManager
game.Players.PlayerAdded:Connect(function(player)
local moneyValue
local success, err = pcall(function()
moneyValue = moneyStore:GetAsync("Player_"..player.UserId)
end)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Cash"
money.Value = 100
money.Parent = leaderstats
if success then
money.Value = moneyValue
else
print("Failed to Load Data")
end
while wait(3600) do
money.Value += 10000
end
local function save(player)
local success, err = pcall(function()
moneyStore:SetAsync("player_"..player.UserId, player.leaderstats.Money.Value)
end)
end
if success then
print("Saved Data")
else
print("Failed to Save Data")
end
end
local function autosave()
while wait(10) do
for i, player in pairs (game:GetService("Players"):GetPlayers()) do
save(player)
end
end
end
remote.OnServerEvent:Connect(function(player, amount)
player.leaderstats.money.Value += amount
end)
spawn(autosave)```
Try this code: local moneyStore = DS:GetDataStore("Money") local remote = game:GetService("ReplicatedStorage").CashManager
game.Players.PlayerAdded:Connect(function(player)
local moneyValue
local success, err = pcall(function()
moneyValue = moneyStore:GetAsync("Player_"..player.UserId)
end)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Cash"
money.Value = 100
money.Parent = leaderstats
if success then
money.Value = moneyValue
else
print("Failed to Load Data")
end
spawn(function()
while wait(3600) do
money.Value += 10000
end
end)
local function save(player)
local success, err = pcall(function()
moneyStore:SetAsync("player_"..player.UserId, player.leaderstats.Money.Value)
end)
end
if success then
print("Saved Data")
else
print("Failed to Save Data")
end
end
local function autosave()
while wait(10) do
for i, player in pairs (game:GetService("Players"):GetPlayers()) do
save(player)
end
end
end
remote.OnServerEvent:Connect(function(player, amount)
player.leaderstats.money.Value += amount
end)
spawn(autosave)
try this, you forgot a ) after an end since you made a :Connect
local moneyStore = DS:GetDataStore("Money")
local remote = game:GetService("ReplicatedStorage").CashManager
game.Players.PlayerAdded:Connect(function(player)
local moneyValue
local success, err = pcall(function()
moneyValue = moneyStore:GetAsync("Player_"..player.UserId)
end)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Cash"
money.Value = 100
money.Parent = leaderstats
if success then
money.Value = moneyValue
else
print("Failed to Load Data")
end
while wait(3600) do
money.Value += 10000
end
local function save(player)
local success, err = pcall(function()
moneyStore:SetAsync("player_"..player.UserId, player.leaderstats.Money.Value)
end)
end
if success then
print("Saved Data")
else
print("Failed to Save Data")
end
end)
local function autosave()
while wait(10) do
for i, player in pairs (game:GetService("Players"):GetPlayers()) do
save(player)
end
end
end
remote.OnServerEvent:Connect(function(player, amount)
player.leaderstats.money.Value += amount
end)
spawn(autosave)
Do you have something outside of the script you are referencing? Because CashManager might have a problem in it. That could be why the save is underlined.
I think I fixed it! When I fixed the save() thing, a new thing got underlined which was the last line and the underlined thing was autosave, it was because you put a local before the function when its inside of another function so the value was not transferring.
local DS = game:GetService("DataStoreService")
local moneyStore = DS:GetDataStore("Money")
local remote = game:GetService("ReplicatedStorage").CashManager
game.Players.PlayerAdded:Connect(function(player)
local moneyValue
local success, err = pcall(function()
moneyValue = moneyStore:GetAsync("Player_"..player.UserId)
end)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Cash"
money.Value = 100
money.Parent = leaderstats
if success then
money.Value = moneyValue
else
print("Failed to Load Data")
end
while wait(3600) do
money.Value += 10000
end
local function save(player)
local success, err = pcall(function()
moneyStore:SetAsync("player_"..player.UserId, player.leaderstats.Money.Value)
end)
if success then
print("Saved Data")
else
print("Failed to Save Data")
end
end
function autosave()
while wait(10) do
for i, player in pairs (game:GetService("Players"):GetPlayers()) do
save(player)
end
end
end
end)
remote.OnServerEvent:Connect(function(player, amount)
player.leaderstats.money.Value += amount
end)
spawn(autosave)