local var = Instance.new("BoolValue")
while true do
var.Value = true
wait(1)
var.Value = false
wait(1)
end
var.Changed:Connect(function()
print("yes")
end)
Changing it to a bool value and using the .Changed event should work.
Apologies, my previous response was under the assumption is was already a bool value.
its not working, i changed my code little bit still not working
local var = Instance.new("BoolValue")
while true do
var.Value = true
wait(1)
var.Value= false
wait(1)
end
var:GetPropertyChangedSignal("Value"):Connect(function()
print("yes")
end)
We would need to implement the :GetPropertyChangedSignal event before the loop, to make sure it registers.
local var = Instance.new("BoolValue")
var:GetPropertyChangedSignal("Value"):Connect(function()
print("yes")
end)
while true do
var.Value = true
wait(1)
var.Value= false
wait(1)
end
The issue with your code is that you are trying to use the Changed event on a variable that is not a Roblox instance. The Changed event is a feature of Roblox instances such as Part , Script , LocalScript , and many others, but not regular variables.
If you want to check when a regular variable has changed, you will need to create your own function to do so. One way to achieve this is to use a combination of a getter and setter function. Here’s an example:
local myVar = false
function getMyVar()
return myVar
end
function setMyVar(value)
if value ~= myVar then
myVar = value
print("myVar has changed!")
end
end
setMyVar(true)
setMyVar(false)