Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index global 'script' (a nil value)?

I'm working on learning private modules and this keeps happening...

script = nil

local module = {}

local children = script:GetChildren()
script = Instance.new("ModuleScript")
for _, child in pairs(children) do
	child.Parent = script
end

return module

Error : attempt to index global 'script' (a nil value) on line 5 (script:GetChildren())

6 comments

0

Not COMPLETELY sure if this is true, but I think it's probably because you're using a ModuleScript instead of Script so therefore 'script' wouldn't work.

0

OH, my bad. I didn't really take the time to really look at what you had on there. Since you have script = nil, that's probably why the script is giving a nil value. You can't get the children of a nil value.

0

I removed it, still getting the error.

0

I'm not sure then. Hopefully someone else might be able to help shed light on your predicament!

1

You realise you have to upload it to the roblox model catalog (can be copylocked) and are ONLY able to use it in ONLINE MODE? (Not in studio solo / server)

1 answer

Listen to your error message, and analyze your code. You've just set global variable script to nil, and then called GetChildren on nil. Private modules are simply just modules that don't need to be present in your game to require them. Instead, you can require their asset id (implying they needed to be uploaded to ROBLOX first), and ROBLOX will import and execute all the code in the required module.

Security

The only reason you'd need code that resembles what you've provided, is if you want to protect your private module's source from being stolen. However, I'm not sure how relevant or reliable implementing something like that would be anymore, because I'm pretty sure ROBLOX changed some permissions when requiring something over their network. I would have to try a few things myself to give you up-to-date information on protecting a module's source code.

1 comment

0

If I just keep script = nil, would I still have some sort of security?

This discussion is preserved as it was. New answers, comments, and votes are closed.