Hi, I’ve been having this EXTREMELY frustrating issue I try and index a key from a table, and then it just says “Nope, not there” and prints out a nil
Here’s my code:
local producables = {
"Factory",
"Barracks"
}
local chosen = nil
local folder = nil
for _,v in pairs(selection:GetChildren()) do
local val = v.Value
if table.find(producables, val) then -- is it a producable? (can it produce stuff)
print('found')
chosen = v.Value
folder = game.ReplicatedStorage.Units[val]
break
end
end
print(folder)
Note: The folder of “Selection” includes stringValues of the selected object. Don’t ask why.
You should probably check to make sure that the Objects you’re getting through inside the Instance are valid Value objects
Try this?
local producables = {
"Factory",
"Barracks"
}
local chosen = nil
local folder = nil
for _,v in pairs(selection:GetChildren()) do
local val = v.Value
print("String's Name: "..v)
print("String's Value: "..val)
if v:IsA("StringValue") and table.find(producables, val) then -- is it a producable? (can it produce stuff)
print('found')
chosen = v.Value
folder = game.ReplicatedStorage.Units[val]
break
end
end
print(folder)