After adding more than 2 intvalues in a data store script the output says the third value is not a valid member of folder (leaderstats) why is this?

(purposely put hyphens btw)

local players = game:GetService("Players")
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("121")
local ds2 = datastore:GetDataStore("121")
local ds3 = datastore:GetDataStore("121")
--local ds4 = datastore:GetDataStore("121")
--local ds5 = datastore:GetDataStore("121")
--local ds6 = datastore:GetDataStore("121")

players.PlayerAdded:connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = "leaderstats"
	folder.Parent = player
	
	local currency1 = Instance.new("IntValue")
	currency1.Name = "Wood"
	currency1.Parent = player.leaderstats
	currency1.Value = ds1:GetAsync(player.UserId) or 0
	ds1:SetAsync(player.UserId, currency1.Value)
	
	local currency2 = Instance.new("IntValue")
	currency2.Name = "Sticks"
	currency2.Parent = player.leaderstats
	currency2.Value = ds2:GetAsync(player.UserId) or 0
	ds2:SetAsync(player.UserId, currency2.Value)
	
	local currency3 = Instance.new("IntValue")
	currency3.Name = "Tas"
	currency3.Parent = player.leaderstats
	currency3.Value = ds3:GetAsync(player.UserId) or 0
	ds3:SetAsync(player.UserId, currency3.Value)
	
--	local currency4 = Instance.new("IntValue")
--	currency4.Name = "Tas"
--	currency4.Parent = player.leaderstats
--	currency4.Value = ds4:GetAsync(player.UserId) or 0
--	ds4:SetAsync(player.UserId, currency4.Value)
	
	currency1.Changed:connect(function()
		ds1:SetAsync(player.UserId, currency1.Value)
	end)
	currency2.Changed:connect(function()
		ds2:SetAsync(player.UserId, currency2.Value)
	end)
	
	currency3.Changed:connect(function()
		ds3:SetAsync(player.UserId, currency3.Value)
	end)
--	currency4.Changed:connect(function()
--		ds4:SetAsync(player.UserId, currency4.Value)
--	end)
end)

3 comments

0

Then make it a valid member

0

Your currency4 names and your currency3 name are the same. Change them and it should work.

1

You also don't need multiple DataStore's. You can just use one and create a table and save the table and set them by indexing it.