Unable to require module script [SOLVED]

Today I made a ModuleScript called “CreateScript” and what it does is creates a script if you use the correct use of the parameters and stuff. I tried requiring the script but then I got the following error.

It always errors when I try to require and I have no Idea what is wrong.

My CreateScript code in my module.

local function CreateScript(Script,Name,Source,Parent)
if Script.ClassName == “Script” then
Script.Name = Name
Script.Source = Source
Script.Parent = Parent

elseif Script.ClassName == “LocalScript” then
Script.Name = Name
Script.Source = Source
Script.Parent = Parent

elseif Script.ClassName == “ModuleScript” then
Script.Name = Name
Script.Source = Source
Script.Parent = Parent

else
warn(“The Script/Object your trying to insert cannot be created with Instance.new function.”)
end

end

return CreateScript

PluginSecurity
This member cannot be used in scripts, but is usable in the command bar and plugins.

As it is in a module, you cannot use it.

1 Like

Yeah but I did use it in the command bar and it has LocalUserSecurity so idk why it is not working.

I think you should try making your function like this.

local module = {}

module.CreateScript =  function(Script,Name,Source,Parent)
if Script.ClassName == “Script” then
Script.Name = Name
Script.Source = Source
Script.Parent = Parent

elseif Script.ClassName == “LocalScript” then
Script.Name = Name
Script.Source = Source
Script.Parent = Parent

elseif Script.ClassName == “ModuleScript” then
Script.Name = Name
Script.Source = Source
Script.Parent = Parent

else
warn(“The Script/Object your trying to insert cannot be created with Instance.new function.”)
end

end

return module

When calling it do

local module = require(mod)

module.CreateScript(parem1, parem2, etc)

OR you are using a local function, I am not completely sure but try what I did above.

1 Like

What do you leave a base script with this code

loadstring(script.Value.Value)()

and below you put a stringvalue
image

and put the code in the value, remember to activate ServerScriptService.LoadStringEnabled

I still get the error for some reason.

Yeah doesn’t work but thanks for trying.

I withdrew my post because i didnt realize you were requiring it from the command bar. I can really only suggest making the function “function module.CreateScript()”

1 Like

It seems to work fine for me, it might be because of your quotation marks inside the post aren’t correct.

Oh ok. Makes sense now,thanks for telling me.

It’s a bug. If there’s nothing wrong with your code. Try reloading the game. I’ve had the same issue countless times.

If it continues, then your code has an error somewhere.

1 Like

Thanks. I restarted Studio and it works now!

Mhm. Glad to help!! (Char limit)

Also one more question. Who do I message to lock this post up after the post got a solution?

No one. Nobody responds to posts with solutions. That I k own of.

Ok. Goodbye and thanks once again for helping me!

1 Like