I have two scripts. One is a module script containing two tables. Another is a server script containing leaderstats and the data store part. How do I save the leaderstats and tables?
Module Script (ReplicatedStorage)
local module = {}
module.Data = { --Creates Data Table
BodyType = {},
BodyColor = {}
}
module.CurrentFluff = { --Sets Current Fluff Variables
BodyType = (""),
BodyColor = (""),
FluffDescription = (""),
FluffInfo = {
FluffName = (""),
FluffGender = ("")
}
}
return module
Server Script (ServerScriptService)
local DataStore1 = game:GetService("DataStoreService"):GetDataStore("DataStore1")
local DataModule = require(game.ReplicatedStorage.Scripts.DataModule)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Money = Instance.new("IntValue", leaderstats)
Money.Name = "Money"
local Gems = Instance.new("IntValue", leaderstats)
Gems.Name = "Gems"
pcall(function()
player.leaderstats.Money.Value = DataStore1:GetAsync(player.UserId .. "Money")
player.leaderstats.Gems.Value = DataStore1:GetAsync(player.UserId .. "Gems")
DataModule.Data = DataStore1:GetAsync(player.UserId .. "Data")
DataModule.CurrentFluff = DataStore1:GetAsync(player.UserId .. "CurrentFluff")
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
DataStore1:SetAsync(player.UserId .. "Money", player.leaderstats.Money.Value)
DataStore1:SetAsync(player.UserId .. "Gems", player.leaderstats.Gems.Value)
DataStore1:SetAsync(player.UserId .. "Data", DataModule.Data)
DataStore1:SetAsync(player.UserId .. "CurrentFluff", DataModule.CurrentFluff)
end)
end)
