local D = game:GetService("DataStoreService"):GetDataStore("AI") local HS = game:GetService("HttpService") game.Players.PlayerAdded:connect(function(P) wait(1) local F = Instance.new("Folder") F.Parent = P F.Name = "Values" local CV,NA = { Money = "BoolValue","Money"; Axe = "BoolValue","Axe"; AppleCount = "NumberValue","AppleCount"; Bread = "NumberValue","Bread"; Bucket = "BoolValue","Bucket"; } for i = 1,5 do if CV == "BoolValue" then local B = Instance.new("BoolValue").Parent == P.Values B.Name = NA elseif CV == "NumberValue" then local N = Instance.new("NumberValue").Parent == P.Values N.Name = NA else print("Error") end local K = P.UserId D:GetAsync("AI", K) end end)
After solving all the errors, for some reason "I = 1,5 do" Isn't actually creating the values. Is there something I did wrong around there?
What I'm basically trying to do is when the player joins the game, For each of CV,NA's values, they create a NumberValue or a BoolValue, depending on CV. then it's named according to NA.
The output when I run this code, just prints "Error".
But I've checked my "if" statements, and I don't understand why it's not confirming/Creating the instances according to CV....
Any help would be appreciated.
You are trying to loop through a table wrong.
for Index = 1,5 do print(Index) end
This would print 1 through 5. A loop like this does nothing else, the only thing that changes is Index
(AKA i
).
What you have to do is actually loop through the table itself:
local Table = { Money = {"BoolValue","Money"}; -->> You can't assign a value to multiple values, put these multiple values into a table instead } -->> One value = one table, you can't split a table up into multiple values -->> In your code, doing so would make NA nil for _,Data in pairs (Table) do -->> Loops through table with Data being the entry in the table local CV,NA = Data[1],Data[2] -->> Get the first and second values in the table local Value = Instance.new(CV) -->> No need for if statements, just use the CV Value.Name= NA -->> Same thing here Value.Parent = F -->> This is how you set a parent, don't use == -->> Also use F since it is better than using P.Values again end
Tips
Formatting
Make sure to format properly - it is super hard to debug/read your code when it's not formatted properly.
GetAsync
Your GetAsync
is useless, and does not work.
This is what you do to make it work:
D:GetAsync(K) -->> GetAsync only has 1 value you can give it, and it is the key
But, it also is useless because you are getting the saved data, but not saving it anywhere.
local SavedData = D:GetAsync(K) -->> Set it to a variable
Hope I helped!
~TDP