The problem is that I don’t know why I can’t write code like this and why the system can’t check if strval and inputtable[whatever number] are the same, is it just not allowed or is there a problem with my code?
Edit: The error lies in the fact the variable rarity is being returned as nil as it is meant to give a capital letter as a string value depending on what strval is entered
It does require; I call the function in a server script and it returns ‘rarity’ as a nil value. In the screenshot, I include a part of the output box that shows the values being returned, the first one that reads nil is what rarity returns
local Inputtable = {
"a",
"b",
"c"
}
local Ascorrespodent = {
"A"
}
function maps2cluefolder.dmfm(strval)
local rarity
-- Case-insensitive comparison
local function caseInsensitiveCompare(a, b)
return string.lower(a) == string.lower(b)
end
if caseInsensitiveCompare(strval, Inputtable[1]) then
rarity = "A"
elseif caseInsensitiveCompare(strval, Inputtable[2]) then
rarity = "B"
elseif caseInsensitiveCompare(strval, Inputtable[3]) then
rarity = "C"
end
print("strval:", strval)
print("Inputtable[1]:", Inputtable[1])
print("rarity:", rarity)
return rarity
end
-- try this script ---
Ah, this didn’t work but it did lead me to my error which had to do with my first function return not being a string value… thank you for your help as my actual issue lies in specific coding which I will have to learn as i get better.
local map2map = {}
function map2map.mrcp(folder)
local children = folder:GetChildren()
if #children > 0 then
local randomChildIndex = math.random(1, #children)
local randomChild = children[randomChildIndex]
return randomChild.Name
else
return nil -- Handle the case where the folder has no children
end
end
return map2map