Problem with camera shaking

  1. Camera shake.

  2. Camera offset moving is not working.

  3. I Tried to make a loop and tried tween service but found nothing useful in the hub.**

This works when I equip the tool, The camera offset is moving only outside of a loop or a tween.

-- game.ReplicatedStorage.CriminalsEquipped.Event:Connect(function(tool)
	Tool = tool
	ContextActionService:BindAction("Shoot", HandleAction, false, Enum.KeyCode.G)
	ButtonConnection = Button.MouseButton1Up:Connect(OnButton)
	local OriginalCamera = Humanoid.CameraOffset
	local TweenService = game.TweenService
	local RandomOffset = Vector3.new(
		math.random(-2.9, 2.9),
		math.random(-2.9, 2.9),
		math.random(-2.9, 2.9)
	)
	TweenService:Create(Humanoid, TweenInfo.new(0.1), {CameraOffset = OriginalCamera + RandomOffset}):Play()
end)
1 Like

firstly, your first line is commented out, and you should be defining tween service before this event function. also is this a client script or a server script? because contextactionservice only works on client.

do you want it to shake when you shoot or when you equip?? because you have to make a function to take advantage of the contextactionservice. you’ve already referenced the HandleAction function, you just need to create it, such as here:

local TweenService = game:GetService("TweenService")

function HandleAction(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		local OriginalCamera = Humanoid.CameraOffset
		local TweenService = game.TweenService
		local RandomOffset = Vector3.new(
			math.random(-2.9, 2.9),
			math.random(-2.9, 2.9),
			math.random(-2.9, 2.9)
		)
		TweenService:Create(Humanoid, TweenInfo.new(0.1), {CameraOffset = OriginalCamera + RandomOffset}):Play()
	end
end

also i don’t know why you have ButtonConnection = Button.MouseButton1Up:Connect(OnButton) because that is not doing anything.