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

Why does the Code fail to get the Module, then return an Error?

Asked by 9 years ago

I have starting using ModuleScripts, but, whenever I use one, it errors if I attempt to get the Model by it's ID.

The error is Unable to find module for asset id, when I had published the Module on the official Website, and got the correct ID.

I fail to understand why I keep getting this error, as it does not make sense to me.

This is the code I have created (one of some of the codes I've made) to get the Module;

if msg:lower():sub(1,3+#Prefix) == Prefix.."ss " then
    local plrz = GetPlr(plr,msg:sub(4+#Prefix))
    for i,v in pairs(plrz) do
        spawn(function()
            if v and v.Character and v.Character:FindFirstChild("Humanoid") and v:FindFirstChild("Backpack") then
                if not require(247523883) then return print("Error occurred!") end
                local ROrb = require(247523883):Clone();
                ROrb.Parent = v.Backpack
                v.Character.Humanoid:EquipTool(ROrb)
            end
        end)
    end
end
0
Your problem is that you're attempting to perform `require` on an ID, when it has to be done on a modulescript. TurboFusion 1821 — 9y
0
The Model I published is a ModuleScript though, also, it does not have to directly be in the game to call the Module, as the person in charge of fixing all of ROBLOX's gears did this. TheeDeathCaster 2368 — 9y
0
Are you sure the asset ID is correct? The script is was published by itself, not in a model or anything? iaz3 190 — 9y
View all comments (7 more)
0
Was it supposed to be in a 'Model' Instance? o_e Also, I thought the ID is correct, because I don't understand it having to create a Second Model of the same thing (Like Decals; There are two copies of the same thing, but perform two separate tasks). TheeDeathCaster 2368 — 9y
0
are you just uploading the module script to ROBLOX? and not like a model with the script in it iaz3 190 — 9y
0
I uploaded the Model with the ModuleScript with it; The Model is inside the ModuleScript, and the ModuleScript is supposed to return it. TheeDeathCaster 2368 — 9y
0
Ro-ORB model? iaz3 190 — 9y
0
Yes, that is the name of the Published 'Ro-Orb Model'. TheeDeathCaster 2368 — 9y
0
Can't figure it out. other modules work just fine. I Believe the problem may be because it contains a model itself. iaz3 190 — 9y
0
Interesting, I didn't know you could use an Asset Id TurboFusion 1821 — 9y

1 answer

Log in to vote
3
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Make sure that the name of the published module in named MainModule, otherwise it won't work as expected.

Note: what I mean by 'name' is the name of the actual instance you uploaded.


Then you can use it with the require function. With arguments of either an asset URL or just the asset ID.


Also, be wary that on line 7 then you're using the clone method directly off of the require method. This will only work if the module you're using the function on returns an instance!

0
Thanks man, this fixed the code! :D But, why is it required to name the Module 'MainModule' for it to work? TheeDeathCaster 2368 — 9y
0
Idk, roblox is silly(: Goulstem 8144 — 9y
0
Yep. Haha! :) TheeDeathCaster 2368 — 9y
Ad

Answer this question