So I got this far with another scripter looking to see if there is anymore insight? Im using a data store system for an inventory. And looking to use this script to add to the data store service without breaking the other store script. This basically creates a leader stats folder under already created data_folder. Im getting errors at end) and wondering if this is even possible?
local DataStoreService = game:GetService("DataStoreService")
if DataStoreService then
local data = DataStoreService:GetDataStore("Data_folder")
local Leaderstats = game:WaitForChild("Leaderstats")
game.Players.PlayerAdded:Connect(function(Player)
if Player then
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Cash = Instance.new("IntValue")
Cash.Name = "Dragoons"
Cash.Value = data:GetAsync(Player.UserId) or 250
data:SetAsync(Player.UserId, Player.leaderstats.Dragoons.Value)
Cash.Parent = Leaderstats
local Resource1 = Instance.new("IntValue")
Resource1.Name = "Wood"
Resource1.Value = data:GetAsync(Player.UserId) or 5
data:SetAsync(Player.UserId, Player.leaderstats.Wood.Value)
Resource1.Parent = Leaderstats
local Resource2 = Instance.new("IntValue")
Resource2.Name = "Iron"
Resource2.Value = data:GetAsync(Player.UserId) or 5
data:SetAsync(Player.UserId, Player.leaderstats.Iron.Value)
Resource2.Parent = Leaderstats
local Resource3 = Instance.new("IntValue")
Resource3.Name = "Stone"
Resource3.Value = data:GetAsync(Player.UserId) or 5
data:SetAsync(Player.UserId, Player.leaderstats.Stone.Value)
Resource3.Parent = Leaderstats
local Resource4 = Instance.new("IntValue")
Resource4.Name = "Metal"
Resource4.Value = data:GetAsync(Player.UserId) or 5
data:SetAsync(Player.UserId, Player.leaderstats.Metal.Value)
Resource4.Parent = Leaderstats
local Resource6 = Instance.new("IntValue")
Resource6.Name = "Cloth"
Resource6.Value = data:GetAsync(Player.UserId) or 5
data:SetAsync(Player.UserId, Player.leaderstats.Cloth.Value)
Resource6.Parent = Leaderstats
-- Adds 250 cash every 2 minutes
if Cash then
while true do
wait(2)
Cash.Value = Cash.Value + 250
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
data:SetAsync(Player.UserId, Player.leaderstats.Dragoons.Value) --Change "Points" to the name of your leaderstat.
data:SetAsync(Player.UserId, Player.leaderstats.Wood.Value)
data:SetAsync(Player.UserId, Player.leaderstats.Iron.Value)
data:SetAsync(Player.UserId, Player.leaderstats.Stone.Value)
data:SetAsync(Player.UserId, Player.leaderstats.Metal.Value)
data:SetAsync(Player.UserId, Player.leaderstats.Cloth.Value)
end)