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).
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.
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.
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.