okay, so I’m making a traffic light system, and I want to prevent people from bypassing it,
so I figured out an idea: detecting when players ignore the red lights
and, my question is… is there any actual way to find the direction a player is heading in from the [object].Touched event?
because currently my system doesnt work, because people that does not skip red lights also get fined because the system false detects players.
To get the actual direction you can use HumanoidRootPart.Velocity, but I don’t see why you couldn’t use Touched instead. Could you show a picture of the current setup? I think the easiest way would be to run Touched on a part stretching the road where players with a red light would enter the intersection.
I can’t use touched, let’s say that a car is coming from east, and want to go to south, but it’s red for the vehicles at the south lane, then the vehicle from east, will get fined for no absoulute reason at all
You only used the touched event to detect which character parts are in the intersection. From there you need to get the character model from the touched body part, and then use either HRP.Velocity for movement direction, or HRP.CFrame.LookVector for facing direction. You will likely want to multiply these vectors by Vector3.new(1,0,1) to project on the the ground plane, just to remove any irrelevant Y-axis component, and then take the dot product with a vector (or vectors, depend on the intersection) that represents the current allowed (green lit) directions of travel, or the stopped directions, whatever your convention is.
The dot product of two vectors facing the same direction will be positive and (1.0 if it’s exactly the same), zero if the vectors are at right angles, and negative if they are pointing away from each other.