Here, I wrote a simple script for you to use to do that. Modify the variable, dist, to the amount of studs the player must be within to set off the alarm. Also, make sure you point the alarm variable to the alarm.
alarm =
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local temp = nil
local dist = 10
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("Torso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while wait() do
target = findNearestTorso(alarm.Position)
if(target ~= nil) then
else
end
end
1 comment
The only problem with that, Panzer is i dont want the thing to be touched I want the find part on ray bit could you change the script to findpartonray() for me please, Thanks