Is there a way to pass arguments through a function in BindToRenderStep?

I’m currently making a camera-shake module for my game. I would like to pass through an intensity argument in the function to adjust the intensity of the shake, but my code relies on BindToRenderStep to work.

Is there a way to pass through arguments in BindToRenderStep?

My code:

function module.initCameraShake(intensity)
	local plr = game.Players.LocalPlayer
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	
	local now = tick()
	
	local bobbleX = math.cos(now * 9) / 2--6
	local bobbleY = math.cos(math.sin(now * 12)) / 2--3
	
	local bobble = Vector3.new(bobbleX, bobbleY , 0) * 5
	
	hum.CameraOffset = hum.CameraOffset:Lerp(bobble, .1)
end

function module.shakeCamera(bool)
	if bool == true then
		runService:BindToRenderStep("CameraShake",Enum.RenderPriority.Camera.Value + 1,module.initCameraShake)
	else
		runService:UnbindFromRenderStep("CameraShake")
	end
end

The most practical way to do this is to call it through a function:

runService:BindToRenderStep("CameraShake", Enum.RenderPriority.Camera.Value + 1, function() 
 module.initCameraShake(...) end)

Just replace the 3 dots with your argument(s). Alternatively, you can use a global variable instead.

6 Likes