My idea is to add strings from a part or model name, I want to purchase a door and insert the name of the door into my players data like a simulator so when the player joins and they have purchased that door already, they can go through it.
Yes these both are module scripts in the “DataManager” Module script.
leaderstats scripts
local module = {}
function module:Create(player: Player, profile)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Diamond = Instance.new("IntValue")
Diamond.Name = "Diamond"
Diamond.Value = profile.Data.Diamond
Diamond.Parent = leaderstats
local Ruby = Instance.new("IntValue")
Ruby.Name = "Ruby"
Ruby.Value = profile.Data.Ruby
Ruby.Parent = leaderstats
local Bronze = Instance.new("IntValue")
Bronze.Name = "Bronze"
Bronze.Value = profile.Data.Bronze
Bronze.Parent = leaderstats
local Silver = Instance.new("IntValue")
Silver.Name = "Silver"
Silver.Value = profile.Data.Silver
Silver.Parent = leaderstats
local Multiplier = Instance.new("IntValue")
Multiplier.Name = "Multiplier"
Multiplier.Value = profile.Data.Multiplier
Multiplier.Parent = leaderstats
end
return module
Template Script:
local Template = {
Diamond = 0,
Ruby = 0,
Bronze = 0,
Silver = 0,
Multiplier = 1,
}
return Template
Incase you need the dataManager script:
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local modules = ServerScriptService:WaitForChild("Modules")
local ProfileService = require(modules:WaitForChild("ProfileService"))
local Template = require(script:WaitForChild("Template"))
local leaderstats = require(script:WaitForChild("Leaderstats"))
local DataKey = "_DataStore"
local profileStore = ProfileService.GetProfileStore(DataKey, Template)
local datamanager = {}
datamanager.Profiles = {}
local function PlayerAdded(player: Player)
local profile = profileStore:LoadProfileAsync("Player_"..player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
datamanager.Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(Players) then
datamanager.Profiles[player] = profile
leaderstats:Create(player, profile)
else
profile:Release()
end
else
player:Kick()
end
end
local function PlayerRemoving(player: Player)
local profile = datamanager.Profiles[player]
if profile ~= nil then
profile:Release()
end
end
for _, player in Players:GetPlayers() do
task.spawn(PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)
return datamanager