What’s in the server script, and where are these scripts placed in the explorer tab?
Just the lines where require
is being called. If multiple scripts are using this module it could be possible that one of them is doing it wrong.
Character selection local script, uses the key to fire the remote,
local securityModule = require(game.ReplicatedStorage:WaitForChild("Security"))
local key = securityModule.GetRandomSecurityKey()
(by Awesom3_Eric)
In the server scripts that use it, I have the exactly same script
The local script is located in a GUI,
the server script is located in the serverscriptservice
try doing
local securityModule = require(game.ReplicatedStorage:WaitForChild("Security"))
local key = securityModule.GetRandomSecurityKey()
print(key)
and see if that prints anything in the output
That error message is only returned if the ModuleScript
errors before returning the value(s).
Your issue is probably in the ModuleScript itself.
If I recall correctly, I encountered a similar bug before, but it fixed itself by restarting studio.
It could be Lua VM spazzing out.
*TL;DR try resetting studio; doubt it’s the scripts which require it.
It prints the key
(30 characters)
Restarted the studio, nothing changed
What is the error again?
The "module experienced an error"
shouldn’t appear if it errors after returning a value.
In the worst case scenario, just use .Key
instead of :GetKey()
.
Great, so the script correctly requires the module. If the error persists, you can either click on the error to find the source, or maybe, press Ctrl + Shift + F and search the word “require” to see if any other scripts are requiring this module.
Otherwise, the key works, and now you have to set up a RemoteEvent to check the key from client to server. If you need help with that we can help you out.
A small question, can _G be a solution?
If so, how to make it?
The last time I tried,
the value returns nil
I must just warn you that this system will not fix any of your security issues. Sanity checks are only way to fix exploiters being able to do stuff they aren’t allowed to. Client-sided keys/checks/whatever are just a barrier which they need to jump over. And in this case, it would be more of a step.
That out of the way, having it in _G
shouldn’t change any behavior, there is something wrong with your code/setup/something since the code works normally on my machine.
(Also, you stated that printing key actually prints a key, so nothing should return nil…)
Could you set a randomKey from a ServerScript and just connect a remote event to check whether or not the key was correct. Players won’t have access to this randomKey, and modules wouldn’t be necessary.
Remote spy can detect the key, however it will keep new people in exploiting from abusing the system, I’m gonna try it
No???
You wouldn’t be able to fire a remote because you don’t have a key on client?
And if you somehow replicate the key to client, what is stopping an exploiter from just copying it?
As @Legoracer pointed out, using a key system won’t really help with security in the first place, regardless of whether its in a shared module script or initialized on the server and sent to clients. In order for your local scripts to send legitimate signals to the server, they would need to know the key. And assuming that exploiters can analyze whatever is on their client, they would have access to the key as well.
I meant, the remote is fired by client when the player clicks on the GUI, it will be fired with all arguments
Just tested the key stored in the server script, works
As I said; it’s not a good system whatsoever.
It would take complete 1 minute to figure it out.
Server sanity checks are the way to go.
Instead of telling server “give me A and deduce my money”, just tell it “buy A” and let server know what that means.
You can do:
local module = {}
funcition module.RemoteSecurity() return math.random(1000000, 9999999) end
return module
Instead if that errors.