I have a basic leaderstats script. I want to modify it to save things that are not numbers and not in leaderstats. How can I do that?
Script:
local dataStore = game:GetService("DataStoreService"):GetDataStore("MoneyData") -- MoneyData is the name of the DataStore.Change it to reset all data.
StarterMoney = 50 -- This is the amount of money new players will have
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats" -- DO NOT CHANGE THIS NAME.PLEASE!
leaderstats.Parent = player
local Currency = Instance.new("IntValue")
Currency.Name = "Money" -- Change "Money" to whatever your currency is named"
Currency.Parent = leaderstats
Currency.Value = dataStore:GetAsync(player.UserId) or StarterMoney
while true do
wait(math.random(2,3))
Currency.Value = Currency.Value+math.random(1,4)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
dataStore:SetAsync(player.UserId, player.leaderstats.Money.Value)
end)
PS. The script is in ServerScriptService and I want the script to be in the same script.

1 comment
u can use variables to save things, you can use a module, or global variable to pass things from the leaderstats script, however what is it exactly what you are waning to save