Hello! I have a leaderboard stats for Money and I have a save data script that's supposed to save the data. Although when I try it, it does not work. Yes, I'm using a Roblox player. If I gain money in a server and then I leave to go in another server I don't have any money at all! I've looked at the output and I see a message that says error saving data. It's said that in the output if it could not save the data, which it's not. Can anyone help me? Btw keep in mind I'm a new scripter and I don't know much. Also, I found this script off of a youtube video.
This is my script. Server Script Service
local DS = game:GetService("DataStoreService")
local moneyStore = DS:GetDataStore("Money")
local remote = game:GetService("ReplicatedStorage").Remotes.GiveCurrency
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 = "Money"
money.Parent = leaderstats
if success then
money.Value = moneyValue
else
print("Error Occured Loading Money")
end
end)
local function save(player)
local success, err = pcall(function()
moneyStore:SetAsync("Player_"..player.UserId, player.leaderstats.Money.Value)
end)
if success then
print("Data Saved")
else
print("Error Occured Saving 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)
I have a folder in the replicated storage and in that folder is a remote event named GiveCurrency. Does anyone know how to fix this?

1 comment
Ok It Did! Thanks!