local AlarmValue = false
local Magnet = script.Parent.Parent.Magnet
local Main = script.Parent
local AlarmActiveValue = game.Workspace["Tan's Technology Dynanc Security Alarm"].Values.AlarmActive
while true do
local Distance = (Main.Position - Magnet.Position).Magnitude
if Distance >= 10 then
AlarmValue = true
if AlarmValue == true then
AlarmActiveValue = true
else if Distance <= 10 then
AlarmValue = false
if AlarmValue == false then
AlarmActiveValue = false
end
end
end
end
end
This code is operated to keep checking if a part is 10 studs away from another part to make a door ocntact sensor work. However, on line 7 (“While True Do”) it keeps not fucntioning.
The error ouput says “Script Timeout: Exhausted Allowed Execution Time”
I am not sure on how to fix it and wondering if anyone could hoepfully help me within fixign this error that is killing my brain.
Do what @SeargentAUS said by not calling “while true do” just call “while wait() do”. This will repeat the upfollowing process but with little debounce so that it doesn’t exceed the processing limit.
local AlarmValue = false
local Magnet = script.Parent.Parent.Magnet
local Main = script.Parent
local AlarmActiveValue = game.Workspace["Tan's Technology Dynanc Security Alarm"].Values.AlarmActive
while true do
local Distance = (Main.Position - Magnet.Position).Magnitude
if Distance >= 10 then
AlarmValue = true
if AlarmValue == true then
AlarmActiveValue = true
else if Distance <= 10 then
AlarmValue = false
if AlarmValue == false then
AlarmActiveValue = false
end
end
end
end
end
task.wait()
The task.wait() needs to be inside the loop, so like this:
local AlarmValue = false
local Magnet = script.Parent.Parent.Magnet
local Main = script.Parent
local AlarmActiveValue = game.Workspace["Tan's Technology Dynanc Security Alarm"].Values.AlarmActive
while true do
local Distance = (Main.Position - Magnet.Position).Magnitude
if Distance >= 10 then
AlarmValue = true
if AlarmValue == true then
AlarmActiveValue = true
else if Distance <= 10 then
AlarmValue = false
if AlarmValue == false then
AlarmActiveValue = false
end
end
end
end
task.wait()
end