Why does camera offset not work?

It doesn’t work in a loop? Code:

game.ReplicatedStorage.Events.CameraShake.OnServerEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local camOffset = char:FindFirstChild(“Humanoid”).CameraOffset
for i = 1,30 do
local rando = math.random(-5, 5)
camOffset = Vector3.new(rando, rando, rando)
print(“done”)
print(camOffset)
wait()
end
end)

please provide more context next time

the reason it is not working is because on line 3, where you make the variable “camOffset”, you put it to Humanoid.CameraOffset.
the variable is reading the property, not referencing it.
to fix this, remove the camOffset variable all together and apply the humanoid’s camera offset manually.

Do you mean by saying: Hum.CameraOffset = [value]? Because if so, I’ve just done that and it hasn’t worked

here is a fixed version of your script, let me know if it errors.

game.ReplicatedStorage.Events.CameraShake.OnServerEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:FindFirstChild(“Humanoid”)
for i = 1,30 do
humanoid.CameraOffset = Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5))
print(“done”)
print(camOffset)
wait()
end
end)

It does absolutely nothing to the players camera, but the script definitely runs as it prints “done”, but with no errors

Hi, try this code in LocalScript

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:FindFirstChild("Humanoid")

for i = 1,100 do
	local randoX = math.random(-80, 80) / 400 -- random offset (X)
	local randoY = math.random(-80, 80) / 400 -- random offset (Y)
	local randoZ = math.random(-80, 80) / 400 -- random offset (Z)
	
	humanoid.CameraOffset = Vector3.new(randoX, randoY, randoZ)
	task.wait(.04)
end

-- normal offset
humanoid.CameraOffset = Vector3.new(0, 0, 0)