Secuirty Alarm Contact Senor

I wish to make like a security alarm door/window contact sensor. So when the magnet is x ammount of studs away from the other part it sets a block of code off. Otherwis eit just keeps checking if it opened.

5 Likes

yeah?? whats the problem?
u can use magnitude for that

5 Likes

My noobish way of doing it would be to just use TouchEnded so if the particular parts aren’t touching anymore then off goes the alarm. Or if you wanted it a certain distance apart then make an invisible part in between and use that for the sensor:

part = script.Parent
part.TouchEnded:Connect(function(otherpart)
	if otherpart.Name == "Sensor" then -- Condition
		print("Alarm set off")
	end
end)

Of course the condition could be anything. Attribute, Tags…whatever

4 Likes

what is magnitude? Like what is that?

4 Likes

the distance between 2 positions

4 Likes

explain i am so confused what do you mean

3 Likes

All I get is it is distance of 2 objects but like can you epxlian it? @MysterySoulESPYT

3 Likes

lets say i have 2 vectors

Vectors
My1stVector = Vector3.new(0,0,1)
My2ndVector =Vector3.new(0,0-,1)

Getting magnitude
(My1stVector - My2ndVector).Magnitude – should be 3 i think

U can check docs to learn more about that
also, if u want someone to do that for u, u could go to talents hub or something like that
U cant tell people to make entire scripts for u

3 Likes

i think i get it thx for ur help

3 Likes
local AlarmValue = false
local Magnet = script.Parent.Parent.Magnet
local Main = script.Parent

local Distance = (Main.Position - Magnet.Position).Magnitude

print(Distance)

if Distance >= 10 then
	AlarmValue = true
	print(AlarmValue)
	
	Main.BrickColor = BrickColor.new("Really red")
	
else if Distance <= 10 then
		AlarmValue = false
		print(AlarmValue)
		
		Main.BrickColor = BrickColor.new("Institutional white")
	end
end

It works!

3 Likes

good job!
i recommend watching other topics or seeing the docs before posting a topic because it may already have the solutions u are wanting

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.