Workspace.Player's Name.LocalScript:40: attempt to perform arithmetic (mul) on number and nil

So i was trying to follow this guys on roblox studio and stuck of this im not good at sintax so pls help

local function GetBobbing(Addition, Speed , Modifer)
	return  math.sin(time()* Addition * Speed )  * Modifer
end

Video : https://www.youtube.com/watch?v=kFpvVTD9-jg&t=617s

watch at 11:12

3 Likes

You are trying to multiply nil and a number. so somewhere along this line

return math.sin(time()* Addition * Speed ) * Modifer

time() or addition or speed or modifer is nil. Try this to see which of them is null

local function GetBobbing(Addition, Speed , Modifer)
        print(Addition)
        print(Speed)
        print(Modifer)
	return  math.sin(time()* Addition * Speed )  * Modifer
end
1 Like
local function GetBobbing(Addition, Speed, Modifier)
    return math.sin(tick() * Addition * Speed) * Modifier
end

-- EXAMPLE:
local Addition = 1
local Speed = 1
local Modifier = 1

local value = GetBobbing(Addition, Speed, Modifier)

Make sure to replace the values of Addition, Speed, and Modifier with the appropriate values for use.

07:37:47.818 Workspace.Player’s Name.LocalScript:43: attempt to perform arithmetic (mul) on number and nil - Client - LocalScript:43
Printed: ( running on cilent side)
07:37:47.833 10
07:37:47.833 1
07:37:47.833 0.2
07:37:47.833 5
07:37:47.833 1.2
07:37:47.833 nil

Still that problem

local player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = script.Parent.Humanoid
local HRP = Character:WaitForChild('HumanoidRootPart')

local Camera = workspace.CurrentCamera

local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local TS = game:GetService("TweenService")
local RelicatedStorage = game:GetService("ReplicatedStorage")

local SpringModule = require(RelicatedStorage.SpringModule) -- try to acces bobbing module

local Viewmodel = game.ReplicatedStorage.Viewmodel:Clone()
Viewmodel.Parent = Camera
local Gunmodel = RelicatedStorage.Ak47
Gunmodel.Parent = Viewmodel
local Joint = Instance.new("Motor6D")
Joint.Part0 = Viewmodel.PrimaryPart
Joint.Part1 = Gunmodel.Handle
Joint.Parent = Gunmodel.Handle
Joint.C1 =CFrame.Angles(0, math.rad(90), 0) *  CFrame.new(0,1.7 ,.2)

local Animations = {
	["Idle"] = Viewmodel.AnimationController.Animator:LoadAnimation(RelicatedStorage.AnimationPack.IdleAk47)
}
Animations.Idle:Play()

local MouseSway = SpringModule.new(Vector3.new())
MouseSway.Speed = 20
MouseSway.Damper = .5

local MovementSway = SpringModule.new(Vector3.new())
MovementSway.Speed = 20
MovementSway.Damper = .4


local function GetBobbing(Addition, Speed , Modifer)
	print(Addition)
	print(Speed)
	print(Modifer)
	return  math.sin(time()* Addition * Speed )  * Modifer -- issue here
end


RS:BindToRenderStep("Viewmodel" , 301 , function(DT)
	local MouseDelta = UIS:GetMouseDelta()
	MouseSway.Velocity  += (Vector3.new(MouseDelta .X / 450,MouseDelta.Y / 450))
	
	local MovementSwayAmount = Vector3.new(GetBobbing(10,1,.2), GetBobbing(5,1.2) , GetBobbing(5,1,.2))
	MovementSwayAmount.Velocity += (MovementSwayAmount/25) * DT * 60 * HRP.AssemblyLinearVelocity.Magnitube
	Viewmodel:PivotTo(
		Camera.CFrame * CFrame.new(MovementSway.Position.X / 2, MovementSway.Position.Y / 2,0)
		*	 CFrame.Angles(0, MovementSway.Position.X, MovementSway.Position.Y)
		*	 CFrame.Angles(0, -MovementSway.Position.Y, MovementSway.Position.X)
		
	
	)
end)

Still same issue i am sure this is a function ?

I see the error. Near the bottom of your code, you don’t provide a third argument to the GetBobbing() function. Add a comma between 1 and .2. This is why your function works fine once, and then errors, because you supply all arguments the first time and only 2 the second time you call the function. Below is what it should end up looking like

local MovementSwayAmount = Vector3.new(GetBobbing(10,1,.2), GetBobbing(5,1, .2) , GetBobbing(5,1,.2))

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