I am trying to create some item Gui’s based on a list of items, however, the name I give the Gui is nil even after it prints the correct name.
Here is my (local) script:
local itemModule = require(game.ReplicatedStorage.ModuleScripts.CreateItems)
local items = itemModule.craftableItems
local function unloadItems(itemsTable)
for i, v in pairs(itemsTable) do
local split = string.split(v, ",") -- "3 wood", "1 stone"
local numberOfTypesOfItems = #split -- 2
local gui = game.ReplicatedStorage.Ui.ItemSample
if gui then
local newGUi = gui:Clone()
newGUi:FindFirstChild("ItemName").Text = i
newGUi.Name = i
for index, value in pairs(split) do
local deepSplit = string.split(value, " ")
local number = deepSplit[1]
local name = deepSplit[2]
print(number, name)
if newGUi and name and number then
local intvalue = Instance.new("IntValue")
intvalue.Name = name
intvalue.Value = number
intvalue.Parent = newGUi
newGUi.Parent = script.Parent
else
return false
end
end
end
end
end
local unload = unloadItems(items)
if not unload then
print("Error when unloading items to craft!")
end
This might be the reason, newGui, name, and number are probably not nil and so it is not returning anything from the function, which therefore, makes unloadItems(items) equal to nil.
Your module doesn’t return anything and the bottom line checks if what unload returns is falsy. Both false and nil are falsy and will fail the if statement because of the not. Change your not condition to check if false is explicitly returned and you’ll no longer have this happen.
if unload == false then
print("Error when unloading items to craft!")
end
Not really proper error handling but I won’t really ask too deeply.
Thanks for your reply. However, I return true once the function (if it does) runs smoothly. Thus, the function should be true. I do not see any way this could become false. I will try your idea though.
It’s a term used to describe a condition where something is considered false in a boolean context. If you’ve heard of truthy or truthiness, falsy or falsiness is the opposite of that. If I don’t say falsy it changes what I say completely because now I’m referring to only false. nil is not false but it is falsy.
In writing:
→ Your module doesn’t return anything and the bottom line checks if what unload returns is false.
This would be incorrect because false is not the only value being checked by an if not (condition) then statement, it checks if the condition is anything but true (existing). False and nil both fail the if statement because of the not there. They’re the opposite of existing.