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()
--code
Beam.NewBeam(tool.Handle.Position, hitPosition, 0.2, Color3.new(1, 1, 1), 0.3)
end
tool.Equipped:Connect(function()
repStore:FindFirstChild("Equipped"):Play()
end)
tool.Unequipped:Connect(function()
repStore:FindFirstChild("Unequipped"):Play()
end)
tool.Activated:Connect(function()
repStore:FindFirstChild("Metal"):Play()
fireWeapon()
end)
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) * CFrame.new(0, 0, -length / 2)
local beam = Instance.new("Part", game.Workspace["Laser Beams"])
beam.Size = Vector3.new(thickness, thickness, length)
beam.CFrame = cFrame
beam.Anchored = true
beam.CanCollide = false
beam.Color = color
beam.Material = Enum.Material.Neon
game.Debris:AddItem(beam, duration)
end
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!