Why does it say this error? "attempt to perform arithmetic (mul) on Vector3 and nil"

I’m having this error while using body velocity for knockback. It’s on the bv.Velocity line.

function module.BodyVelocity (parent, HRP, Knockback, stayTime)
	local bv = Instance.new ("BodyVelocity")
	
	bv.MaxForce = Vector3.new(math.huge,0,math.huge)
	bv.P = 50000
	bv.Velocity = HRP.CFrame.LookVector * Knockback
	bv.Parent = parent
		
	Debris:AddItem(bv,stayTime)
end

It appears your argument Knockback is nil, double check and make sure Knockback is either a number or Vector3.

Because the knockback is nil, meaning when youre calling this function your third argument is nil you can confirm this by doing print(Knockback)

Yeah printed it and it’s nil. I’m using a module script for the knockback stats. Something probably went wrong with it. The location for it is correct I just checked. I’ll send over the entire script.

local module = {}

-- Services 
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local StarterPlayer = game:GetService("StarterPlayer")
local SoundService = game:GetService("SoundService")
local Debris = game:GetService("Debris")

-- Folders 
local WeaponsSounds = SoundService.SFX.Weapons
local RSStorage = RS.Storage
local RSModules = RSStorage.Modules
local SSModules = SS.Modules 
local Events = RSStorage.RemoteEvents

-- Events
local CombatEvent = Events.Combat
local VFX_Event = Events.VFX


-- Modules 
local SoundsModule = require(RSModules.Combat.SoundsModule)
local ServerCombatModule = require(SSModules.CombatModule)
local WeaponStats = require (SSModules.Weapons.WeaponStats)

function module.BodyVelocity (parent, HRP, Knockback, stayTime)
	local bv = Instance.new ("BodyVelocity")
	
	bv.MaxForce = Vector3.new(math.huge,0,math.huge)
	bv.P = 50000
	bv.Velocity = HRP.CFrame.LookVector * Knockback
	bv.Parent = parent
		
	Debris:AddItem(bv,stayTime)
end


function module.Normal_HitboxHit(plr,char,weapon,Hitbox,...)
	local HitAnim = ...
	Hitbox.OnHit:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= char then
			local eChar = hit.Parent
			local eHum = eChar:FindFirstChild("Humanoid")
			local eHRP = eChar.HumanoidRootPart
			
			if eHum.Health > 0 then 
				local WeaponStat = WeaponStats.getStats(weapon)
				local damage = WeaponStat.Damage
				local knockback = WeaponStat.Knockback
				print (knockback)
				print (damage)
					
				eHum:TakeDamage(damage) 
				
				ServerCombatModule.stopAnims(eHum)
				
				VFX_Event:FireAllClients("CombatEffects", RSStorage.VFX.Combat.Blood, hit.CFrame, 3)

				SoundsModule.PlaySound(WeaponsSounds[weapon].Combat.Hit, eChar.Torso)
				
				eHum.Animator:LoadAnimation(HitAnim):Play()
				
				module.BodyVelocity (char.HumanoidRootPart, char.HumanoidRootPart, knockback, .2)
				module.BodyVelocity (eHRP, eHRP, knockback, .2)
				
			end
			
		end
	end)
end
return module

And this is the module that’s getting all the stats.

local module = {}

local info = {
	["Fists"] = {
		Damage = 7.5, 
		Knockback = 5
	},

	["Katana"] = {
		Damage = 12, 
		Knockback = 6.5
	}
}


function module.getStats (weapon)
	return info 
end

return module


I think you need to change your getStats function to this:

function module.getStats(weapon)
    return info[weapon]
end

EDIT: Assuming the weapon argument is a string

2 Likes

Yeah that worked :sob: It’s always the most simple stuff that gets me

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.