Check if player is in zone

what i am trying to achieve is making a tool handle lit up when you are inside of a not-colliding part (zone) and stop it if you leave it.

1 Like

Try using the proximity prompt feature

1 Like

what?? no this is not how it works.

1 Like

Oh, like the tool tips like a light and it lights up when you’re close?

1 Like

local distance = (Character.PrimaryPart.Position - part.Position).Magnitude

if distance < part.Size.Magnitude then
–whatever you want to happen
end

this code detects when you get close to an object named “part”

just change variables and add RenderStepped if your code is on a local script or HeartBeat if it is on Server

1 Like

how do i check when the player activates a tool in that distance?

1 Like

local distance = (Character.PrimaryPart.Position - part.Position).Magnitude

if distance < part.Size.Magnitude then
–whatever you want to happen
end

fire this when the player activates the tool and check if distance is within the desired range

1 Like

Use a touch interest type script that fires a remote event that signals a int value to enable, which if it’s enabled, print that they’re using a tool.

1 Like

how do i detect if a plaayer uses a tool while in that range? without touching events?

1 Like

and also without raycasting? is that possible?

1 Like

local distance = (Character.PrimaryPart.Position - part.Position).Magnitude

if distance < part.Size.Magnitude then
–whatever you want to happen
end

fire this when the player activates the tool and check if distance is within the desired range

here

1 Like

is this eficent if i want to make enemies chack if hit by sword? i mean if they close enough?

1 Like

yup, you can check every time a frame renders if you’re close enough to your enemy to hit him

1 Like

btw this isn’t laggy unless you run a super complex code

1 Like

and how to hit him then? how fo i connect multiple spawning enemies to multiple possibler players that hit it?

1 Like

in this case you can get a table with all the enemies on a localscript.

Then check if your player is close to any of them using a for loop and if they are you can know exactly what enemy you’re close to and fire a RemoteEvent to damage him

1 Like

any way without localscript? or aint that possible?

1 Like

it is however it might be a little bit laggy

1 Like

so how do i do it? so how do i do it?

1 Like

i need the enemy after it spawned to automatically be connected to events (using objectvalues?)

1 Like