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

[SOLVED] ObjectValue's Value is being nil?

Asked by 8 years ago

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.

1 answer

Log in to vote
0
Answered by
einsteinK 145
8 years ago

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.

0
Mhhh... I think I got a way to fix this. Do you know how to check if you'r game is in Online Mode? Since I can make it so the Scripts removes itself if the game doesn't run in Online Mode. manchester1002 57 — 8y
0
Eh, that won't help. If they can run it in studio, they can also just remove the code that checks for online mode. But if you really want to know, check the wiki page for "RunService", it has some methods that could help. einsteinK 145 — 8y
Ad

Answer this question