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.
yeah?? whats the problem?
u can use magnitude for that
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
what is magnitude? Like what is that?
the distance between 2 positions
explain i am so confused what do you mean
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
i think i get it thx for ur help
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!
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
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.