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

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

Asked by 2 years ago
Edited 2 years ago

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

0
If the problem is in the ModuleScript, why don't you give the code Xapelize 2658 — 2y
0
Also did you sure pointTable is nil and not pointstoGet is nil in the StarterGui script Xapelize 2658 — 2y
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 IAmFancyBobert 0 — 2y
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 IAmFancyBobert 0 — 2y

3 answers

Log in to vote
0
Answered by 2 years ago

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.

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. IAmFancyBobert 0 — 2y
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. NotThatFamouss 605 — 2y
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? IAmFancyBobert 0 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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!)

Log in to vote
0
Answered by 2 years ago

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!

Answer this question