How to making something happen when near (like screenshake when something)

I need help making something to where you are near a part the camera starts to shake, I am using EZ camera shaker.

I’ve been looking for it but I cant find anything related to something like this.

i cant really code anything like this so ive been trying to look for a script on the toolbox but no luck.

I would recommend trying to write your own code (for various reasons), but here’s something that could help:

local part = --The part you have to be near
local plr = game.Players.LocalPlayer
local char = plr.Character
local root = char.PrimaryPart

while wait(0.1) do
    local rootPos = root.Position
    local partPos = part.Position
    local distance = (rootPos - partPos).Magnitude
    local requiredDistance = 10 -- Change this to however near you want the player to be for the camera to shake

    if distance <= requiredDistance then
        -- Enable your camera shake script here
    end
end

This is the best I can do with the information you have given. I hope this helps, if you have any questions feel free to ask!

1 Like

You could just make a box even flat if you liked. Lock it down and with full transparency.
Then take everything off but can touch … and drop a script like this in it.

local ftf = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if ftf then ftf = false
		     -- hit.Parent   would end up being the players cam to shake
			task.wait(-- the shake time)
			ftf = true
		end
	end
end)

This would save you the constant loop going.
Edit: added a bit more to that for a first time flag.

i tired this a few days ago and it said something along the lines of “part failed to index character something something”

Doesn’t EZCS support this?

– hit.Parent would end up being the players cam to shake
/facepalm Read that wrong… thought you tried the script I posted a few days ago.

Did you set part = to your part? I think that’s probably your problem, I couldn’t really write anymore of the script for you, but if you show me your explorer I could maybe help more.