So I have this script that should change depending on if the thing is ready or not, but it times out and also does not do what its supposed to, any help?
while true do
if script.Parent.Parent.Ready.Value == false then
script.Parent.Value = "You Cannot Use This Right Now"
elseif script.Parent.Parent.Ready.Value == true then
script.Parent.Value = "Click To Use Controller 2"
end
end
script.Parent.Parent.Ready.Changed:Connect(function(newValue)
if newValue == false then
script.Parent.Value = "You Cannot Use This Right Now"
elseif newValue == true then
script.Parent.Value = "Click To Use Controller 2"
end
end)
Alternatively:
script.Parent.Parent.Ready.Changed:Connect(function(newValue)
script.Parent.Value = newValue and "Click To Use Controller 2" or "You Cannot Use This Right Now"
end)
As to not spoonfeed, I connected to an assumed BoolValue object’s .Changed event, which is fired every time the Ready value is changed, so you would only have to change script.Parent.Value when this value changes.
Your script is timing out because your while true loop never waits before checking the value again, resulting in checking the value probably every few milliseconds or so, and overloading your computer.
If somebody wants to explain the concept of events more clearly, feel free to do so!
The poster above posted a great solution that uses events instead of loops.
If you’re curious why your script times out, it’s because the loop dosen’t have any wait()'s. Since the loop is infinite, it will run over and over super quickly, resulting in it timing out. However, if you add a wait() the loop would run slightly slower keeping it the just right speed.
I don’t think it even waits at all. Milisecond-delayed code still runs, as does code bound to frames. It just hogs the task scheduler in its first iteration and keeps going.