Fire Alarm Dector Help Script

Hey! I am making a fire alarm and I wish for some code to how a dection part that detects smoke or fire in a rage of 40 studs from the dector part. Can anyone help me?

You can’t really request a code here. If you’re asking how you’re gonna do that, on the top of my head, I’m thinking of measuring the distance between the fire and the smoke detector and checking if it is within the range. Check the distance by finding the difference in their position. This is how you do the distance checking:

local Fire = workspace.FirePart
local Detector = workspace.SmokeDetector
local distance = (Detector.Position - Fire.Position).Magnitude
if Magnitude < 50 then
    -- do stuff
end

Yh that might work ille periment it in a min ocne i get this mesh improted

there is one issue, fire isnt there on startup say if a admin uses btools and sets something on fire within range of 50 studs

This is probably rlly ineffective but maybe create a 50 stud block and constantly check what’s inside of it and if it’s fire then detect it?