Hey need help with this if you dont mind!! Im making a multidata store for my inventory system. I also have a datastore for my leaderstats, This script currently doesnt break anything but doesnt save the data like it should. I tried making a second datastore aka datastore2 that could save the leaderstats seperately… just didnt work anyone know how to get what Im after in this script?
Sorry for the pastebin whole script was to large.
Repost was posted in wrong topic.
https://pastebin.com/embed_js/QXK7xYLg
2 Likes
Anyoneeeeee helppp I can explain more if need be.
instead of using a big code, try doing this:
local DataStoreService = game:GetService("DataStoreService")
local testdata = DataStoreService:GetDataStore("SurvivalsData")
game.Players.PlayerAdded:Connect(function(Player)
local LeaderstatsFolder = Instance.new("Folder")
LeaderstatsFolder.Name = "leaderstats"
LeaderstatsFolder.Parent = Player
local TestStat = Instance.new("IntValue")
TestStat.Name = "testaaa"
TestStat.Value = testdata:GetAsync(Player.UserId) or 0
TestStat.Parent = LeaderstatsFolder
end)
game.Players.PlayerRemoving:Connect(function(Player)
testdata:SetAsync(Player.UserId, Player.leaderstats.testaaa.Value)
end)
you can do that for every stat.
as for the items, you can store them in a table and then save them.
When I delete the inventory scripts because there is a profile service, constant script, all within the data setter script the whole inventory breaks. The profile service is what creates the table. Is there code that I could add, that just adds leaderstats values in to the already set “data_folder”
Or even a second script that creates leaderstats into the already made datastore. Without breaking the first datastore.
If I remove the leaderstats and datastore 2 from the profile service script. Then the data saves but I will lose my leaderstats. And if I add a second script that creates leaderstats then both data stores break because you can’t have 2 running.
Would this work as a separate script? And not break the first?
local DataStoreService = game:GetService(“DataStoreService”)
If DataStoreService then
local testdata = DataStoreService:GetDataStore(“data_folder”)
game.Players.PlayerAdded:Connect(function(Player)
local Resources = Instance.new(“Leaderstats”)
Resources.Name = “Resources”
Resourced.Parent = Player
local TestStat = Instance.new("Cash")
Cash.Name = "testaaa"
Cash.Value = testdata:GetAsync(Player.) or 250
TestStat.Parent = LeaderstatsFolder
end)
game.Players.PlayerRemoving:Connect(function(Player)
testdata:SetAsync(Player.UserId, Player.leaderstats.testaaa.Value)
end)
the Instance,new(“Cash”) isn’t right, due to how there’s no such instance as ‘cash’, you have to do it as a value.
also rename the teststat to Cash
Would it have to be a global data store or just get data store
uhhh just get data store i guess? ( i dont use global data store as much )
Getting end) error
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)
^ is there a way to make this work?