How to make a specific npc that makes the screen shake everytime it walks if its near (HELP)

my script is this and its not working local NPC = game.Workspace.NPC
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local shakeAmount = 0.5
local debounce = false

local function calculateDistance(npcHead, playerHead)
return (npcHead.Position - playerHead.Position).magnitude
end

NPC.ChildAdded:Connect(function(child)
if child:IsA(“Humanoid”) then
local distance = calculateDistance(child.Head, player.Character.Head)
child.Humanoid.Changed:Connect(function(property)
if property == “WalkSpeed” and child.Humanoid.WalkSpeed > 0 and distance < 20 and not debounce then
debounce = true
while true do
local shake = Vector3.new(math.random(-shakeAmount, shakeAmount), math.random(-shakeAmount, shakeAmount), math.random(-shakeAmount, shakeAmount))
camera.CFrame = camera.CFrame + shake
wait(0.01)
end
elseif property == “WalkSpeed” and child.Humanoid.WalkSpeed == 0 then
debounce = false
end
end)
end
end)

Are you getting any error codes?

1 Like

There’s no error code. I checked everything and tried to fix it it’s still not working though.