So the problem is that the ObjectValue his Value is nil. I know why it's being set to nil I just don't know how to fix it.
So I got a ServerScript requiring a ModuleScript. Now the thing is I don't want people to steal my ModuleScripts code.
ModuleScript that is being required:
------- PREVENT STEALING: local MS = Instance.new("ModuleScript") script.Parent = MS
Now inside the ModuleScript(the ModuleScript that's required) I have a ServerScript. And in the ServerScript is a Folder called GUIS. With all my ScreenGui's.
ServerScript:
local Player = game:GetService("Players").LocalPlayer local GUIS = script:WaitForChild("GUIS") function InsertGui(Plr, String) local PlrGui = Plr:FindFirstChild("PlayerGui") if PlrGui and GUIS:FindFirstChild(String) then for i, v in pairs(PlrGui:GetChildren()) do if v.Name == String then v:Destroy() end end local Gui = GUIS[String]:Clone() local OV = Instance.new("ObjectValue") OV.Name = "OV" OV.Value = script -- Inside the LocalScript this becomes nil. OV.Parent = Gui Gui.Parent = PlrGui end end InsertGui(Player, "CmdsGui") -- And "YES" the CmdsGui is in the Folder.(In-case you're asking.)
Now there is a LocalScript inside the CmdsGui.
The error happens in the LocalScript.
LocalScript which is inside the CmdsGui:
local Gui = script.Parent local OV = Gui:WaitForChild("OV").Value -- Becomes nil. -- Ok, so now OV's Value is nil... -- It's because I set the required ModuleScript's Parent to something that is nil. -- If I don't do that it works fine, but I don't want my code to be stolen...
Important notes: My game is FilteringEnabled.
So... how to fix this? I already tried to solve this with RemoteFunctions still "nil". Please tell me if you need more information. You're a hero if you solve this ;). Thank you for your time.
The modulescript is required on the server. It only exists on the server, as it isn't replicated to the client. (It doesn't see it in Workspace, StarterPack, its PlayerGui, ...)
If you give the client a reference to something that only exists on the server, it becomes nil. This is both the case for ObjectValue.Value or arguments in RemoteEvents/Functions.
The solution for your case would be: Making the modulescript parent the OV directly to the player's PlayerGui. (or ReplicatedStorage maybe)
You can't protect stuff from being stolen if the client HAS to see it.