Hey there, my name is ShieldDevs. I’m a scripter and a game developer.
So I’ve been working on my game “Escape the Unknown”, which is a scary game. And I wanted to make it so when the player is in light, the flashlight will turn off, and if the player is in a dark place, or not close to light, then the flashlight will turn on. So how can I achieve this?
I don’t believe there is anyway to use lighting and touch events together.
But you could try creating a hidden part that “when touched” and its associated light is on, could achieve a similar goal. Perhaps attempt to shape the part you use so it matches the light dispersion shape.
Thank you for you reply, I thought about that, but the thing is, I don’t know a “perfect” way to check if the player isn’t touching that part. Touch ended is a really bad way to do it, and Magnitude isn’t the best as well.
In my experience. TouchEnded works best if you envelope the player inside the object first. (inside the part == touching, outside the part touch end. Otherwise you’ll probably have to rely on a pattern of raycasts. Oh you can also double check “touchended” by using “GetTouchingParts” when touchended fires. If your still touching the part then debounce it.
there is more than 1 way.
for example region3 or Ray Casting.
But ray casting won’t do the job because the light covers some volume and not just somewhere specific.
Thus create Region3 (s) and check if the player is in that region.
There is no point in connecting and firing an event the part is touched.
If part could be a replacement of Region3 I do not think roblox would have added a separate class.
Region3 and distance checking do not provide a method of activation where touched does. So you must continously check to see if a player is within the region or what the distance is. That requires a while loop or heartbeat check all the time for every light source.
if you want it to be inaccurate/isnt core to the game just get the corners of the player and save those points then create a ray cast with those points to the light sources in your game and if any of them are true they should be in light. A much easier way would be if your game has like spot lights and they are all a constant range just check how far your player is from each light source
Check the character’s humanoid root part vs Light.Parent.Position magnitude and then check the range of the light with (rootpart.Position - Light.Parent.Position).Magnitude < Light.Range, you can add all the lights into a table and loop through that table to have it work, the other way around would be to use GetPartsBoundInRadius(Light.Parent.Position,Light.Range,params)