My code cant find my function in my module script

I have a module script that is supposed to make a beam for my laser gun (based off of the tutorial on dev hub). The problem is, I keep getting the error message NewBeam is not a valid member of ModuleScript "Players.FinnBotF11.PlayerScripts.Beam. I have the module script (called Beam in the variable and script name) in playerscripts, and I have also tried it in replicated storage.

My code in the local script (starterPlayerScripts) calling the module function:

local tool = script.Parent
local repStore = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Beam = Players.LocalPlayer.PlayerScripts:FindFirstChild("Beam")

local function fireWeapon()
	Beam.NewBeam(tool.Handle.Position, hitPosition, 0.2,, 1, 1), 0.3)


My code in the module script (also in starter player scripts):

local Beam = {}

function Beam.NewBeam(startPos, endPos, thickness, color, duration)
	local length = (startPos - endPos).Magnitude
	local cFrame = CFrame.lookAt(startPos, endPos) *, 0, -length / 2)

	local beam ="Part", game.Workspace["Laser Beams"])
	beam.Size =, thickness, length)
	beam.CFrame = cFrame
	beam.Anchored = true
	beam.CanCollide = false
	beam.Color = color
	beam.Material = Enum.Material.Neon

	game.Debris:AddItem(beam, duration)

return Beam

I can send the other code I left out in my first code block if needed, although I don’t think it will make a difference. This worked when I used the code they say to do in the tutorial, but I wanted to remake it on my own (I have never done a fps game, or raycasting, and I wanted to learn). I appreciate any help!

you have to require the module


local Beam = require(Players.LocalPlayer.PlayerScripts:FindFirstChild(“Beam”))

^not sure if this is how you write it

Have you tried including the module script with the ‘require’ keyword?

local Beam = require(Players.LocalPlayer.PlayerScripts.Beam)

EDIT: It might also be better to place the module script in ReplicatedStorage instead. Not sure if you’ll have problems with it being in the above path.

Omg I am stupid sometimes. How could I forget require. smh. K sorry about this I have no idea how I missed that. tysm

I moved it from there when it wasnt working, but I will move it back again. Ty!

That wouldn’t have been the biggest problem… but it just looks like it might be problematic to me…

1 Like