I know you can perform a function once a value's value is changed BoolValue.Changed:connect()
but what if you had this:
Choice=0
And then there's a button that will do something like this Choice=1
after you click it...
Is it possible to have the script detect whether Choice has changed? I'm looking for a way out of having to make an actual instance for a value every time.
Thank you.
You can use MessageOut for scripts to communicate with scripts.
local msg = Instance.new("Message", workspace) Game:GetService("LogService").MessageOut:connect(function(Message, Type) msg.Text = "The message was "..Message.." and the type was "..tostring(Type) end) print("Hello, World!")
local check = 0 local num = 0 function warn() print("The value has changed") end game:GetService("LogService").MessageOut:connect(function(message) if string.sub(message,1,5) == "check:" and tonumber(string.sub(message,6)) ~= check then check = tonumber(string.sub(message,6)) warn() end end) while wait(1) do --Just to change the value of num num = num+1 print("check:"..num) end
Quite complicated but easy, hope this helps!
You can make an instance to support a specific value:
Assuming that there's aleady a script that changes the value of the NumberValue and
V
is a reference to the NumberValue:
V.Changed:connect(function(changed) if changed == 1 then --run code end end)
Alternatively, here's how you could do it in a script without effecting other code in the script using coroutines.
coroutine.resume(coroutine.create(function() while true do if changed == 1 then changed == 0 --run code end wait() end end))
Here you go, something actually relevant
Choice = 0 BoolValue.Changed:connect(function(change) if change == "Value" then --if boolvalue.Value has changed Choice = BoolValue.Value --set the choice to the new value end end)