Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can I not read this challenge table?

Asked by 5 years ago
local comMod= script.Parent:WaitForChild('ModuleScript');
local background = comMod.WaitForChild(script.Parent, 'background');
local main = comMod.WaitForChild(script.Parent.Parent, 'Main');
local questButton = comMod.WaitForChild(background, 'quests');
local questFrame = comMod.WaitForChild(main, 'questFrame');
local challengeFolder = comMod.WaitForChild(main, 'Challenges');
local challenges = {};

---// variables am i rite

function insertChallenge(challenge)
    print('adding '..challenge..' to the Challenges Table!');
    local amount = #challenges
    table.insert(challenges, (amount+1), challenge)
    print(challenges[amount+1]);
    return challenges[amount+1];
end

function removeChallenge(number)
    table.remove(challenges, number)
    return true;
end

function updateChallenges()
    for i = 1,#challengeFolder:GetChildren() do
        wait();
        local name = challengeFolder:GetChildren()[i].Name
        print(challenges[i]);
        if challenges[i] == name then
            print(name..' is already in the Challenge Table!');
            return true;
        elseif challenges[i] ~= name then
            print(name..' does not exist in the Challenge Table, adding it now!');
            insertChallenge(name);
            return challenges.name;
        end
    end
    end




questButton.MouseButton1Click:connect(function()
    script.Disabled = true;
    updateChallenges();
    questFrame.Visible = not questFrame.Visible
    script.Disabled = false;
end)


So, for some reason in the 3rd function, updateChallenges(), whenver I check to see if the challenge is already in the table, it will not read it and say it is not in the table?

0
you need to use require to access functions inside ModuleScripts; local comMod = require(script.Parent.ModuleScript) User#23365 30 — 5y
0
But when I do that, it errors out the whole script, when I don't it works fine up til that point? LilHat57 35 — 5y
0
show us the module script User#23365 30 — 5y
0
Nevermind, it's because I put the module function as, module.WaitForChild(function() instead of module.WaitForChild = function(), but it still won't read the table correctly. LilHat57 35 — 5y

Answer this question