Datastore not loading inventory?

I’m essentially trying to create a saving inventory called “Relics”. When a player joins, it doesn’t create any values in the “Relics” folder. There is no error message.

Script:

local DataStoreService = game:GetService("DataStoreService")
local pointsStore = DataStoreService:GetOrderedDataStore("Points")
local minutesStore = DataStoreService:GetOrderedDataStore("Minutes")
local RelicsStore = DataStoreService:GetDataStore("Relics")

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Relics = Instance.new("Folder", Player)
	Relics.Name = "Relics"
	
	local Points = Instance.new("IntValue", leaderstats)
	Points.Name = "Points"
	
	local MinutesPlayed = Instance.new("IntValue", leaderstats)
	MinutesPlayed.Name = "Minutes Played"
	
	local MaxScraps = Instance.new("IntValue", Player)
	MaxScraps.Name = "MaxScraps"
	MaxScraps.Value = 3
	
	local Scraps = Instance.new("IntValue", Player)
	Scraps.Name = "Scraps"
	Scraps.Value = 0
	
	local AccumulatedPoints = Instance.new("IntValue", Player)
	AccumulatedPoints.Name = "AccumulatedPoints"
	
	local AccumulatedMinutes = Instance.new("IntValue", Player)
	AccumulatedMinutes.Name = "AccumulatedMinutes"
	
	local AllPoints
	local AllMinutes
	local RelicInventory
	local success, response = pcall(function()
		AllPoints = pointsStore:GetAsync(Player.Name)
		AllMinutes = minutesStore:GetAsync(Player.Name)
		RelicInventory = RelicsStore:GetAsync(Player.UserId)
	end)
	
	AccumulatedPoints.Value = AllPoints or 0
	AccumulatedMinutes.Value = AllMinutes or 0
	
	if RelicInventory then
		for i, v in pairs(RelicInventory) do
			local Relic = Instance.new("ObjectValue", Relics)
			Relic.Name = v
		end
	end
	
	local OldPoints = Points.Value
	local NewPoints
	Points:GetPropertyChangedSignal("Value"):Connect(function()
		NewPoints = Points.Value
		local Difference = NewPoints - OldPoints
		game.ReplicatedStorage.MoneyChanged:FireClient(Player, Difference)
		OldPoints = NewPoints
	end)
	
end)

game.Players.PlayerRemoving:Connect(function(Player)
	pointsStore:SetAsync(Player.Name, Player.AccumulatedPoints.Value)
	minutesStore:SetAsync(Player.Name, Player.AccumulatedMinutes.Value)
	local RelicInventory = {}
	for i, v in pairs(RelicInventory) do
		table.insert(RelicInventory, v.Name)
	end
	RelicsStore:SetAsync(Player.UserId, RelicInventory)
end)

Make sure you’re parenting the values to the relics folder itself.

Ex.

local MaxScraps = Instance.new("IntValue", Player)
	MaxScraps.Name = "MaxScraps"
	MaxScraps.Value = 3
        MaxScraps.Parent = Relics

Also make sure the relics folder is being put somewhere.

Update I realised you’re setting the parent in the instance.new parameters, however the API says

Try it underneath how I explained and see if that fixes anything

1 Like

It didn’t work. Anything else I could try? Anyways the issue isn’t anything with MaxScraps, it’s just the part where it creates relic values and saves them.

I’ll look into this further, but my second solution is adding print statements, specifically where you’re having the issues. Ex. Maybe a print statements for the values you’re saving/loading. Also, sorry when you say having relics is the issue that it’s not saving in datastore? Or is it that it won’t load upon return?

1 Like

Won’t load upon return. Let me try adding some print statements to figure out the issue. :+1:

I just realize I figured it out… it was a typo. Thanks for your help.

1 Like

No problem :+1:

||chrsssssssssssss||

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.