My LocalScripts aren't working with ModuleScripts?!

local MEGAMODULE = require(game.ReplicatedStorage.Assets.MEGAMODULE)
print(MEGAMODULE.GamepassIds.VIP)

image

The local script works fine in studio, but not when you play the actual game. All of my local scripts don’t work because of this. Help!

You may wanna try to do this:

local MEGAMODULE = require(game:GetService("ReplicatedStorage"):WaitForChild("Assets").MEGAMODULE)

I could be wrong though.

There should be another error in the modulescript itself which you need to include.

It works fine in studio with both server scripts and local scripts. If there was an error, wouldn’t there be a problem when testing in studio?

not necessarily, it could be you are trying tio access a part of the UI that is not loading in yet but since studio has all the players assests loading in already an actual game might have errors that are found in the actual game then in studio. Anyway, We need to see the code mostly what around line 2 but the whole code is preffered

The script shown in the original post was the entire example script. I just only copy and pasted the actual code. Sorry for the inconvenience.
image

What he means is the Module Script, not the Local Script.

1 Like

Okay, then. Here’s the module script.

local MEGAMODULE = {}

--Game Children

MEGAMODULE.Workspace = game.Workspace

MEGAMODULE.Players = game.Players

MEGAMODULE.Lighting = game.Lighting

MEGAMODULE.ReplicatedFirst = game.ReplicatedFirst

MEGAMODULE.ReplicatedStorage = game.ReplicatedStorage

MEGAMODULE.ServerScriptService = game.ServerScriptService

MEGAMODULE.ServerStorage = game.ServerStorage

MEGAMODULE.StarterGui = game.StarterGui

MEGAMODULE.StarterPack = game.StarterPack

MEGAMODULE.StarterPlayer = game.StarterPlayer

MEGAMODULE.SoundService = game.SoundService

MEGAMODULE.Chat = game.Chat

MEGAMODULE.LocalizationService = game.LocalizationService

MEGAMODULE.TestService = game.TestService

--Important Objects

MEGAMODULE.Assets = MEGAMODULE.ReplicatedStorage.Assets

MEGAMODULE.Products = MEGAMODULE.ReplicatedStorage.Products

MEGAMODULE.RemoteEvents = MEGAMODULE.ReplicatedStorage.RemoteEvents

MEGAMODULE.GameVariables = MEGAMODULE.ReplicatedStorage.GameVariables

--GUI

MEGAMODULE.GUIHoverSoundId = 341225236

MEGAMODULE.GUIClickSoundId = 720166642

MEGAMODULE.GUICoinSoundId = 131323304

MEGAMODULE.GUIPurchaseSoundId = 254003734

--Animations

MEGAMODULE.ShakeItemAnimationId = 5541660901

MEGAMODULE.HoldItemAnimationId = 5541842504

return MEGAMODULE

I got a solution! Thanks, CSquad!
image
Turns out, I was setting the variables to things that didn’t load yet. Instead of referring to objects with a dot, I used :FindFirstChild().

The FindFirstChild doesnt affect the existance of Instances, using it will just return nil if not found. That is something that was preventing the module from an error. The error you got is usually when you have an error in your module script. So I suggest using :WaitForChild() when you really know ur stuff exists.

1 Like

The FindFirstChild doesnt affect the existance of Instances, using it will just return nil if not found.

I know. I was just looking for a quick fix, and it worked. I’ll keep :WaitForChild() in mind for the future.

1 Like