Hello. Fyi I am not sure of how to say this but I will try the best I can.
I want my script to wait until another script is disabled but I do not want to calculate how long it would take.
Sample script (to make things easier because it may already be hard without much detail)
Script 1
while true do
--[[starting up
starting up
starting up]]
game.workspace.script2.Disabled = false
wait(?)--this is the problem area i want it to wait until script2 is disabled again
--[[shutting down
shutting down
shutting down]]
end
Script 2
--[[stuff happening
stuff happening
stuff happening
stuff happening
stuff happening]]
script.Disabled = true --the timer will stop in script1 when this line of code is used.
If i didn’t explain my question correctly i would be very happy to answer any questions
You could use the GetPropertyChangedSignal method, which listens for a change with a specific property. In this case, you could do the following:
while (not Script2.Disabled) do -- Checks if the property's not disabled
Script2:GetPropertyChangedSignal("Disabled"):Wait(); -- Listens for a change with the property
end
You shouldn’t even be disabling scripts at runtime. And it isn’t even reliable.
consider this code
script.Disabled = true
print("Won't print")
while true do
print("Prints bro")
wait(1)
end
Instead, look into using the conditional part of a while loop to do something, when the loop breaks consider that “disabled”. Never touch the disabled property.
local disabled = false
while not disabled do
-- ...
-- later on disable
disabled = true
end
Here’s a question: why do you need to do this? It sounds like you could just use a single script with ModuleScripts containing the other components of your code or just using BindableEvents.
It’s in cases like this why developers typically recommend not using multiple scripts, because you have several entry points for code which result in race conditions and lead to you doing things like waiting for another script to be disabled. This thread almost plays out like an XY problem.