"Sensor" Activated Script

Hello fellow developers. I’m very new to scripting, and I’m currently trying to learn new ways of triggering/activating a script, as I only kinda how to activate one using an on-touch script. Any help is greatly appreciated.

Some areas I need to activate scripts for:

-When a player walks into a room

-When a player sits down

-When a player is near a certain object

-Other “sensor” related activations

Here’s wiki links to things that should help you figure out each problem you’re trying to solve I have to run to work so I can’t help more than this right now, but I’m sure the other lovely people of the dev forum can!

Room: Region3

Sit: Humanoid.Seated event
Near object: (firstVector3 - secondVector3).magnitude (Make one vector by taking our first position (the HumanoidRootPart, and the object you’re trying to check the distance one, and grab the .magnitude, or the length of the vector)

1 Like

Thanks for the links and info. The seated event seems simple enough, but the other two seem like they’ll take a bit longer to learn.

1 Like

Well, actually they are all pretty similar. You can use the touched event to see when the player walks into the room by simply having a part that is transparent and doesn’t collide, at the entrance or the entire room.

2 Likes

You can use a touched event! So firstly make a part in a door or something and name it “Censor” and insert a script inside.

--Variables
local censor = script.Parent --case sensitive
local door = censor.Parent --case sensitive

--Functions
function OnTouch()
--what happenes when you step on the censor
end

--Touched event comes into place

censor.Touched:Connect(function()
OnTouch()
end

1 Like

Check out my response!

2 Likes

Thanks for the reply! I don’t yet know cFrame very well, or pretty much anything in the functions you wrote, but I’m sure if I study this It’ll lead me to my answer lol.

You can rely on a multitude of things.

As others have mentioned, Region3 for areas, but here’s a short list of other methods:

When you need to check if something has already happened, use if statements. E.g., to check if the player has enough cash.

1 Like