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

Index nil when trying to get something from a moduel script?

Asked by 3 years ago

So theres a moduel script with a name then group id (This is a example)

local Divisions = {
    {
        Name = "First Order";
        GroupId = 39596;
    };
        MainGroup = 39596;
    }

return Divisions

And I have another script thats suppost to read it take the groupid then compair it with your rank in that group to know if you can see a thing on gui that lets you get a certin morph. But its saying

 Players.Ems_Squad.PlayerGui.MorphSelection.Scripts.LocalScript:177: attempt to index nil with 'GroupId' 

And im not sure why.

Here is the part of the script where its erroring:

for i,v3 in pairs (MorphsDir[Divisions[i].Name]:GetChildren()) do

    local Allowed = true

    if v3:FindFirstChild("Rank") then
        if Player:GetRankInGroup(Divisions[i].GroupId) >= v3:FindFirstChild("Rank").Value then --error line
            Allowed = true
        else
            Allowed = false
        end
    end
if Allowed then
    print("Allowed)
end

Thank you in advanced.

0
Is this script part of a bigger script? and are you require'ing the Module script from the ReplicatedStorage folder?, Ill see what i can come up with TGazza 1336 — 3y
0
The top one is the script its in a folder called "Libs" in replicated storage the middle one is the error the lower one is a part of a bigger script Ems_Squad 58 — 3y

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
3 years ago
Edited 3 years ago

not sure if this is how you have your scripts but.

In your Module script:

local Divisions = {
    {
        Name = "First Order",
        GroupId = 39596
    },
    {
        Name = "Roblox Wiki",
        GroupId = 127081
    },
    MainGroup = 39596;
}
--// functions for grabbing the Group(s) by name And ID they both return the table where the group is found
function Divisions:GetGroupByName(Name)
    for i=1,#self do
        local Group = string.lower(self[i].Name) == string.lower(Name)
        if(Group == true) then
            return self[i]
        end
    end
    warn("Warning: Group Name of "..Name.." Not Found!")
    return nil
end


function Divisions:GetGroupById(id)

    for i=1,#self do
        local Group = self[i].GroupId == id
        if(Group == true) then
            return self[i]
        end
    end
    warn("Warning: Group Id with "..id.." Not Found!")
    return nil
end
return Divisions

And for your Local script:

local MorphsDir = workspace.MorphsDir
local Player = game.Players.LocalPlayer
local Divisions = require(game:GetService("ReplicatedStorage")["Divisions Module"])

--// List all the groups you want to deal with in here...

--// this Group table is just for show 
local Groups = {"First Order","Roblox Wiki"}

local isAllowedin = {}

for j=1,#Groups do
    local Group = Divisions:GetGroupByName(Groups[j])
    for i,v3 in pairs (MorphsDir[Group.Name]:GetChildren()) do
        local Allowed = false
        if v3.Name == "Rank" then
            --print(Player:GetRankInGroup(Group.GroupId), v3.Value)
            if Player:GetRankInGroup(Group.GroupId) >= v3.Value then
                Allowed = true
            else
                Allowed = false
            end
        end
        if(Allowed == true) then
            isAllowedin[#isAllowedin+1] = Group.Name
        end
        --print(Group.Name," = ",(Allowed == true and "Is" or "Not") .. " Allowed")
    end
end

--// print out the names of the groups that this player is allowed in
print("Player Named [",Player.Name,"] is allowed in ...")
for k,v in pairs(isAllowedin) do
    print("\t ",v)
end

Non DisplayTable Example:

local MorphsDir = workspace.MorphsDir
local Player = game.Players.LocalPlayer
local Divisions = require(game:GetService("ReplicatedStorage")["Divisions Module"])

local Group = Divisions:GetGroupByName("First Order")
-- or 
-- local Group = Divisions:GetGroupByName(39596)
if(Group == nil) then error("Warning:Group is nil!") end

for i,v3 in pairs (MorphsDir[Group.Name]:GetChildren()) do
    local Allowed = false
    if v3.Name == "Rank" then
        if Player:GetRankInGroup(Group.GroupId) >= v3.Value then
            Allowed = true
        else
            Allowed = false
        end
    end
    print(Group.Name," = ",(Allowed == true and "Is" or "Not") .. " Allowed")
end

Link to download my working example here: (7z File link deletes in 2 days!)

http://www.fileconvoy.com/dfl.php?id=gaf547c2824471e4e1000335551932e11c9ecc2a4d5

Hope this helps in some way. You may need to change a few things to get it working.

Let me know if you need more info

0
Hey! that wont work due to what it is the script im trying to do is if the armor has a varible called "Rank" then it checks your rank in the group if you have that rank or higher then it will let you see it. But its not doing that. Ems_Squad 58 — 3y
0
I dont need a total new script I just need to somehow fix the little part it was working before now it isnt. Ems_Squad 58 — 3y
Ad

Answer this question