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

{fixed, read the answer i posted} module script keeps returning nil no matter what i do?

i'm trying to make a shouting sim esq game with some friends and due to my lack of proper knowledge of decent scripting i can't figure out how to get the module script to not return nil

(yes we are aware about the roblox audio purge we'll find a way around it)

the server script (event handler)

--// Variables
local rs = game.ReplicatedStorage
local ss = game.ServerStorage
local sss = game.ServerScriptService

local pointScript = require(rs.ModuleScripts.EpicPoints)

--// Functions

--// addPoints function

local function addPoints(plr,points)
	local plrPoints = ss.Points:FindFirstChild(plr.Name)
	
	plrPoints.Value += points
	
end

--// Shout function

local function shout(points,plr)
	addPoints(points,plr)
end


--// Shouted event

rs.Events.Shouted.OnServerEvent:Connect(function(points,plr)
	shout(points,plr)
end)

the startergui script (button stuff)

--// Variables
local plr = game.Players.LocalPlayer

local rs = game.ReplicatedStorage
local ss = game.ServerStorage
local sss = game.ServerScriptService

local ui = script.Parent

local shoutButton = ui.ShoutButton
local shoutNumber = shoutButton.ShoutNumber

local pointScript = game.ReplicatedStorage.ModuleScripts.EpicPoints
local pointTable = require(pointScript)

--// Main script


--// Shout button clicked

shoutButton.MouseButton1Click:Connect(function()
	
	local pointsToGet = pointTable[shoutNumber.Value]
	
	print(pointsToGet)
	
	rs.Events.Shouted:FireServer(pointsToGet,plr)
end)

any help as to why this is happening is appreciated

btw the module script is nothing much, just 2 values in the table

4 comments

0

If the problem is in the ModuleScript, why don't you give the code

0

Also did you sure pointTable is nil and not pointstoGet is nil in the StarterGui script

0

i didn't give the code to the module script Xapelize because as i said, it's just 2 lines of code that have different values

0

also the problem is getting the values from the module script, i did it in a local AND server script and both didn't work, they just returned nil

3 answers

You didn't make any call to ModuleScript for it to return. You need to call the Module's function, for example:

Module

local mod = {}

function mod.Test()
	print("Test")
end

return mod

Server (or Client)

local mod = require(script.ModuleScript)

mod.Test()

Output:

Test

I don't know what's the function to call your module, but with this, you should be able to debug it easily.

3 comments

0

i don't have a function inside the module script, it's just 2 things with the values of 1 and 2. i'm trying to make a quick and simple point giving system because number values have a cap and that's not really ideal for a shouting sim fangame being as the numbers go to astronomical heights.

0

You should make a function inside of it just like what I did. I advise using IntValue instead of NumberValue, and watch some ModuleScript tutorials.

0

both number and int values have a limit (to my knowledge) though, and i'm using the module script to store the amount of points each thing gives. should i still make a function to keep the point amounts in though?

Try change the Value of Variable pointScript in the 2nd script to rs:WaitForChild("ModuleScripts"):WaitForChild("EpicPoints")

local pointScript = rs:WaitForChild("ModuleScripts"):WaitForChild("EpicPoints")

Hope the answer helping you :)

(Or maybe just see that guy answer, might help you too!)

nevermind; i fixed it

the problem was the module script itself apparently, i moved the points table to a server script and it worked fine from there on

no clue why the module script was doing that, but atleast it works now. thanks for the suggestions!

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