Need help with datastore table/for loop

I have a table function and a for loop which cycles through a table and puts each value I want in the respected folder, however it doesn’t do this and it prints no error and I do not know why, my assumption is it only does one check and put everything in the first check which I do not know how to fix!
Help would be greatly appreciated!

Script :

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Undertale2")

local Generator = {

	["BoolValue"] = {"Sans", "Rainbow", "Smoke", "Souls", "NitroBooster", "Pumpkin", "TrueStick", "SansGun", "SansSword", "FortniteGun", "BobBlade", "TemStick", "Bandage", "FadedRibbon", "ManlyBandana", "OldTutu", "CloudyGlasses", "TemmieArmor", "StainedApron", "CowboyHat", "HeartLocket", "TheLocket", "Owner", "Tester", "Contributor", "Staff"};
	["IntValue"] = {"Hair", "SkinTone", "Shirt", "Pants"}

}


function ValueCreator(ValueType, Name, Folder, Values)
	if ValueType and Name then
		local ValueInstance = Instance.new(ValueType, Folder)
		ValueInstance.Name = Name
		ValueInstance.Value = Values
	else
		warn("ValueType was not found")
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	
	task.wait()
	
	local Custom = Instance.new("Folder", Player)
	Custom.Name = "Customization"
	
	local Skins = Instance.new("Folder", Player)
	Skins.Name = "Skins"
	
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"
	
	local ChatVal = Instance.new("Folder", Leaderstats)
	ChatVal.Name = "ChatValues"
	
	local PlayerVal = Instance.new("Folder", Leaderstats)
	PlayerVal.Name = "PlayerValues"
	
	local Armor = Instance.new("Folder", Player)
	Armor.Name = "Armor"
	
	for index, value in pairs(Generator) do
		for index2 = 1, #value do
			if #value == "Hair" or "SkinTone" or "Shirt" or "Pants" then
				task.spawn(ValueCreator,index,value[index2],Custom,1)
			elseif #value == "Sans" or "Rainbow" or "Smoke" or "Souls" or "NitroBooster" or "Pumpkin" or "SansGun" or "FortniteGun" or "BobBlade" or "TemStick" then
				task.spawn(ValueCreator,index,value[index2],Skins,false)
			elseif #value == "Owner" or "Tester" or "Contributor" or "Staff" then
				task.spawn(ValueCreator,index,value[index2],ChatVal,false)
			elseif #value == "Bandage" or "FadedRibbon" or "ManlyBandana" or "OldTutu" or "CloudyGlasses" or "TemmieArmor" or "StainedApron" or "CowboyHat" or "HeartLocket" or "TheLocket" then
				task.spawn(ValueCreator,index,value[index2],Armor,false)
			end
		end
	end
	
	local TP = Instance.new("DoubleConstrainedValue", PlayerVal)
	TP.MinValue = 0
	TP.MaxValue = 999
	TP.Name = "TP"
	TP.Value = 0

	local EXP = Instance.new("DoubleConstrainedValue", Leaderstats)
	EXP.MinValue = 0
	EXP.MaxValue = 15850000
	EXP.Name = "EXP" 
	EXP.Value = 0

	local LV = Instance.new("DoubleConstrainedValue", Leaderstats)
	LV.MinValue = 0
	LV.MaxValue = 100
	LV.Name = "LV" 
	LV.Value = 1

	local G = Instance.new("DoubleConstrainedValue", Leaderstats)
	G.MinValue = 0
	G.MaxValue = 999999999999999999999999999
	G.Name = "G" 
	G.Value = 0

	local R = Instance.new("DoubleConstrainedValue", Leaderstats)
	R.MinValue = 0 
	R.MaxValue = 5
	R.Name = "Resets"
	R.Value = 0
	
	local plrkey = "id_"..Player.UserId
	local save1 = Player.leaderstats.EXP
	local save2 = Player.leaderstats.LV
	local save3 = Player.leaderstats.G
	local save4 = Player.leaderstats.Resets
	local chatvals = Player.leaderstats.ChatValues
	local ownerchat = chatvals.Owner
	local contribchat = chatvals.Contributor
	local Staffchat = chatvals.Staff
	local Playervals = Player.leaderstats.PlayerValues
	local TP = Playervals.TP

	local GetSaved = DataStore:GetAsync(plrkey)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
		save3.Value = GetSaved[3]
		save4.Value = GetSaved[4]
		ownerchat.Value = GetSaved[5]
		contribchat.Value = GetSaved[6]
		Staffchat.Value = GetSaved[7]
		TP.Value = GetSaved[8]
	else
		local NumberForSaving = {save1.Value, save2.Value, save3.Value, save4.Value, ownerchat.Value, contribchat.Value, Staffchat.Value, TP.Value}
		DataStore:GetAsync(plrkey, NumberForSaving)
	end
end)




game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync("id_"..Player.UserId, {Player.leaderstats.EXP.Value, Player.leaderstats.LV.Value, Player.leaderstats.G.Value, Player.leaderstats.Resets.Value, Player.leaderstats.ChatValues.Owner.Value, Player.leaderstats.ChatValues.Contributor.Value, Player.leaderstats.ChatValues.Staff.Value, Player.leaderstats.PlayerValues.TP.Value })
end)

Function line 11 - 20
Table line 4 - 9
For loop line 44 - 56

1 Like

Why are you comparing a number to a string?
Also, I don’t know if this is wrong, but aren’t you suppose to be doing:

if #value == "Hair" or if #value == "SkinTone" or if #value == "Shirt" or if #value == "Pants" then

It doesn’t seem to work at all? Plus it just results in an error I’ve tried comparing many things but they all just end up in the same result so I don’t know.

You’re comparing the amount of strings there are to one of the strings. What is your goal?

I was comparing the values or the table so I can make values in the player the function is there as a value creator, my goal is to make values in the player, if you see task.spawn(ValueCreator,index,value[index2],Skins,false) this should make values in the player based on the if function and the table if they are named what the if function requires

If you want to check if a table has a certain value, do:

if table.find(TABLE, VALUE) then -- table.find is a int. If it's nil it doesn't exist.

end