Error in my gun system code

Im getting an error on this certain part on my code and im very confused im currently making a gun system and keep getting this error when I shoot a dummy.

Error:
Argument 1 missing or nil
Stack Begin
Script ‘Players.jake_4543.PlayerGui.Client.Modules.Framework’, Line 237
Stack End

FRAMEWORK:

function gun.Shoot(weapon)
			if debounce == false then
				debounce = true	
				local muzzlePos = weapon.Main:WaitForChild("Muzzle").Position
				local wm = require(weaponModules:FindFirstChild(weapon.Name))
				local velocity = weapon.Main.Eject.CFrame.LookVector * 20 + Vector3.new(0,30,0)
				local ejectPos = weapon.Main.Eject.Position
				local ejectOr = weapon.Main.BulletOrientation.Orientation
				spawn(function()
					if muzzlePos then
						rayCastInfo = script.Parent.Parent.Parent.Server.Events.Fire:InvokeServer(muzzlePos,mouse.Hit.p,weapon.Name,{["Vel"] = velocity,["Pos"] = ejectPos,["Or"] = ejectOr}) --Line where its erroring
					else
						rayCastInfo = true	
					end
				end)
				--spawn(function()
					repeat wait() until rayCastInfo ~= nil
					if rayCastInfo ~= true then
						spawn(function()
							gun.Bolt(weapon)
							gun.Recoil(weapon)
						end)
						local dam = rayCastInfo["Damage"]
						local hpp = rayCastInfo["HitPart"]
						local isHumanoid = rayCastInfo["IsHumanoid"]
						local isDead = rayCastInfo["IsDead"]
						if isHumanoid == true and isDead == false then
							if dam and hpp then
								print(dam)
							end
						end
					end
				--end)
			
				wait(60/wm.RateOfFire)
			
				debounce = false
			end
		end

SERVER:

script.Parent.Events.Fire.OnServerInvoke = function(player,from,to,weaponName,bulletCaseTable)
	local it = nil
	if player.Name == script.Parent.Parent.Parent.Name then
		local wm = require(gunModules:FindFirstChild(weaponName))
		
		if (player.Character.HumanoidRootPart.Position - from).Magnitude <= (wm.GunLength * 5) then
			if shootDebounce == false then
				shootDebounce = true
				ejectCase(wm,bulletCaseTable.Vel,bulletCaseTable.Pos,bulletCaseTable.Or)
				spawn(function()
					createFireSound(player,weaponName)
				end)
				local infoTable = raycastModule.Raycast(from,to,1,"-"..wm.Spread,wm.Spread,player,weaponName)
				it = infoTable
				wait(60/wm.RateOfFire)
				shootDebounce = false
			else
				return true
			end
		else
			player:Kick("Possible exploiter. If this persists report to game owner.")
		end
	else
		player:Kick("Possible exploiter. If this persists report to game owner.")
	end
	return it
end

Any help would be appreciated.

Have you put the entire script cuz your script does not have line 237 (If i replied something wrong bare me i am extremely new to development

No, I haven’t put the entire script but I put a comment next to the line that’s erroring.

Oh sorry i didn’t scroll all the way through i am on mobile

1 Like

Your argument muzzlePos is either nil or missing so check if you referring to it right

I know that i’ve been trying to trace that back for the past hour, the object exists.

Im printing the position and its position is fine.

Try printing it after you make the variable muzzlePos.

Thats what I done. I just said I done that

Oh then i am not seeing any problem in the script.I am extremely sorry.

What I would advise here is making your arguments into a tuple. Then printing the arguments as they are received on the server this will allow you to see exactly what is nil and is missing. It will also give you better visual of what arguments are which. Btw, I also advise when writing in the table, putting the name first then the value. Also this error may have something to do with your raycast function if it is returning an error when you have to deal with hit detection.

Sorry about this but i ended up finding it out, I wasnt sending enough info to this 1 function I edited the title to fit this but it got changed back. Anyway now that you replied and cause I made this i can mark this as a solution sorry for wasting your time but either way thanks for taking time to even try help :slight_smile:

no problem! I am happy to help!