'Shoot is not a valid member of ModuleScript' (nope, I'm just dumb :D)

Hello fellow developers!
I have a rather puzzling problem I just can’t seem to figure out.

Problem:
I’m trying to call the ‘Shoot’ function in this ModuleScript from my Local Script ‘Gun’, however as the error below states, ‘Shoot’ cannot be found.

The code within the module used to be in the client script - which absolutely used to work, but to create cleaner and more re-usable code, I separated the two.

I also added a simple ‘Print’ function to the ModuleScript to see if the issue lay in the parameters or body of the shoot function, however, the same error occurs.

Client Script (called 'Gun')
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent


local handle = tool:WaitForChild("Handle")
local barrel = player.Character:FindFirstChild("Barrel") or handle:Clone()
barrel.Name = "Barrel"
barrel.Anchored = true
barrel.CanCollide = false
barrel.Transparency = 0
barrel.LocalTransparencyModifier = 0
barrel.Parent = player.Character

local shootModule = game.ReplicatedStorage:WaitForChild("ShootModule")
local offs,equipped,MB1,targetWall,debounce,status = Vector3.new(),false,false,nil,0,0
local reloadTime = 1
local rateOfFire = 1.2
local caliber = 1.5


function Fire()
	local from = barrel.Position-- and barrel.Position or (handle and handle.Position or player.Character.PrimaryPart.Position)--tool:FindFirstChild("Barrel") and tool.Handle.Position or player.Character.PrimaryPart.Position
	local too = barrel.Position + (barrel.CFrame.LookVector*(mouse.Origin.p-mouse.Hit.p).Magnitude)
		+ Vector3.new(
			math.random(-100,100),
			math.random(-100,100),
			math.random(-100,100)
		)/1000 * (mouse.Origin.p-mouse.Hit.p).Magnitude * 0.02
	
	shootModule.Shoot(player,from,too,barrel,rateOfFire,caliber)
end


function Reload()
	debounce = reloadTime
end

tool.Deactivated:Connect(function() MB1 = false end)
tool.Activated:Connect(function() MB1 = true

	while MB1 do
		Fire()
		wait()
	end

end)

tool.Equipped:Connect(function()
	mouse.TargetFilter = player.Character
	equipped = true
end)
tool.Unequipped:Connect(function() equipped = false end)


game:GetService("RunService").RenderStepped:Connect(function(dt)
	debounce = debounce > 0 and debounce - dt or debounce
	if (equipped) then
		--if (offs == nil) then
			offs = player.Character.Head.CFrame:ToObjectSpace(handle.CFrame).p - player.Character.Head.Velocity/100
		--end
		local cf = workspace.CurrentCamera.CFrame * CFrame.new(offs)
		barrel.CFrame =  CFrame.new(cf.p, mouse.Hit.p) * CFrame.Angles(math.rad(debounce * 30),0,0) * CFrame.new(debounce,debounce*1.5,debounce*2)
		barrel.LocalTransparencyModifier = 0
	end
end)
Module Script (called 'ShootModule')
local m = {}

local actionRemote = game.ReplicatedStorage:WaitForChild("ShootRemote")
local debounces = {}


m.CreateProjectile = function (player,caliber)
	local projectile = Instance.new("Part")
	projectile.Anchored = true
	projectile.CanCollide = false
	projectile.BrickColor = BrickColor.White()
	projectile.Size = Vector3.new(1,1,2.5) * caliber
	projectile.Parent = player.Character
	projectile.Transparency = 0
	projectile.LocalTransparencyModifier = 0
	Instance.new("BodyForce",projectile).Force = Vector3.new(0,projectile:GetMass() * workspace.Gravity,0)
	return projectile
end

m.Render = function (player,from,too,caliber)
	local p = m.CreateProjectile(player,caliber)
	p.CFrame = CFrame.new(from,too) * CFrame.Angles(0,0,math.random(0,360))
	p.Velocity = (p.CFrame.LookVector*999).Unit * 300

	game.Debris:AddItem(p,1)
	p.Touched:Connect(function(hit)
		local valid = player and player.Character and hit and not player.Character:IsAncestorOf(hit)
		if (valid) then
			p:Destroy()
			actionRemote:FireServer(
				from,
				too,
				p.Size
			)
		end
	end)
end

m.Print = function(msg)
	print(msg)
end

m.Shoot = function (player,from,too,barrel,rateOfFire,caliber)
	print("Mod",player,from,too,barrel,rateOfFire,caliber)
	local debounce = debounces[player.Name] or 0
	if ((debounce) > math.random(0,3)*rateOfFire/10) then print("Debounce",player,debounce) return end
	debounce = rateOfFire
	debounces[player.Name] = debounce

	m.Render(
		player,
		from,
		too,
		caliber
	)
end


return m
Explorer window

When I fire the gun, this error occurs

If you could please take a moment to check over my code, perhaps even test it yourself, I would be very greatful. :slight_smile:

Thanks
-David

5 Likes

Looks like you forgot to require the shootModule :stuck_out_tongue:

10 Likes

LOL!

Dang its been too long since I developed on Roblox.
Cheers mate. :smiley:

4 Likes