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

[Solved] How Would I Run a Function From a Module Script?

Asked by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

I am attempting to make a Holo script where you can run your own function for a leaderstat value, but I get the error;

:99: attempt to index a nil value

Sorry if it does not appear I have attempted this code enough but it is the only way I can think of (Of course I will be providing two scripts with this Question).

This line is inside the Holo Script

set=require(script.Settings)
--98 other lines of code lie here...
for _,v in pairs(set.StatsAvailable) do
    if select(2,pcall(v[3])):match(' ') then
        warn('Function for ' .. v[1] .. ' stat is invalid.')
        warn(select(2,pcall(v[3])))
    end
end

Edited to make this line easier to read.

The above script should be going through all the functions provided in the StatsAvailable table (in the module script below). But it will return the nil value error.

These lines are inside the Settings Module

local settings = {
StatsAvailable = {

    {
    'Rank',
    'StringValue',
    (function()
        game.Players.PlayerAdded:connect(function(Player)
            repeat wait() until Player:FindFirstChild('leaderstats')
            repeat wait() until Player.leaderstats:FindFirstChild('Rank')
            Player.leaderstats.Rank.Value = "Elite"
        end)
    end)
    }

}

}
return settings

I know running functions from a Module Script is possible, I have seen it done in Epix Incorporated Server Suite.

Any help would be appreciated. Thank you. If you need more details, feel free to leave a comment. If you know the answer, please answer this. I am new to Modules, and I think help on this will help me improve. Once again, thank you for reading.


Solved

It seems that my problem was over-complication. In the first code block, I was attempting to if it found to use the warn method. I just rewrote the code to something cleaner in and it works, it will even fire a warning if there is an error.

for _,v in pairs(set.StatsAvailable) do
    local suc,err = pcall(v[3])
    if not suc then warn('Function for ' .. v[1] .. ' stat is invalid.') warn(err) end
end

Thank you for attempting to help.

0
Which line is the source of the error? You say :99: but obviously that's not where it is here. TaslemGuy 211 — 9y
0
It's the Holo script, the first script I provide. I used pcalls on the functions I am trying to obtain to avoid error caused by the person who created the function (I plan to make the script public). The error is basically telling me that the function does not exist when it looks like it does. M39a9am3R 3210 — 9y
0
Trust me, you do not want the full 200 lines of code, I bet if BlueTaslem were to see it he'd say to try to make my code more efficient and stuff like that. M39a9am3R 3210 — 9y
2
It looks to me like you're overcomplicating this thing. What, exactly, are you trying to achieve with the first code block? adark 5487 — 9y

Answer this question