.Changed not working on cloned scripts or after passing through BindableEvents

Problem

I'm 90% sure this is a bug and even filed a bug report. But in the case that I missed something crucial here's what I'm having trouble on.

You can clone a script via :Clone() and it’ll create a facsimile of itself and run the code inside of it.

If you clone a script with this code print("Hello world!") it’ll print out Hello world!.

But if a script with this code is cloned workspace.Value.Changed:Connect(function() print("A") end), assuming you have a IntValue Named Value inside workspace and you changed it’s Value (either via command, or Inspector), nothing will print out.

Same goes for if you binded a function to a BindableEvent and pass an Object Pointer towards the IntValue and execute the same code.

I’ve already tried using :GetAttributeChangedSignal() with and had no luck.

Code (Cloning)

The cloning problem is why I filed the bug report and I intend to add the Bindable Event to it later.

I already have made a place file where this occurs here. Bug.rbxl (18.1 KB)

Code (BindableEvent)

For reasons I can’t share the whole script but here’s the file structure and watered down versions of scripts I’m using.

  • workspace
    • Folder
      • Folder
        • Script2
      • Script1
      • BindableEvent
    • Value (IntValue)

Script1
Event = script.Parent.Event

function FireEvent()
	Event:Fire({Object = workspace.Value})
end

FireEvent()
Script2
Event = script.Parent.Parent.Event
function Main(Data)
	print("started")
	
	local Object = Data.Object

	if not Object then error("Invalid Format.") end
	
	Object.Changed:Connect(function()
		print("Changed")
	end)
	
end
Event.Event:Connect(function(Data) Main(Data) end)

Afterwards I tired to change Script 1 like so

Script1 Changed
function Main()
	workspace.Value.Changed:Connect(function()
		print("Changed")
	end)
end
Main()

But it still doesn’t work. Which is weird to me because running the same exact code in the command console ingame works, and prints out Changed whenever the value is changed.

This leads me to believe that either .Changed is now deprecated and I didn’t hear about it or I’m missing some crucial thing that makes it not functional.

Summary

Please let me know if it works for you or not or if I made an error with the way I wrote .Changed. I double checked to make sure that there wasn’t any syntax errors. There was nothing printed out to the console at all. Like before I’m highly sure that this is a bug but I wanted a second view on things.

Definitely not a bug, something’s wrong with your implementation.

if Data.Object doesn’t exist then it’ll error right there instead of storing Object as nil, should’ve been

 if Data:FindFirstChild("Object") then
 --  pass callback to Object.Changed:Connect() here
 end

image

From the code in the test file, it looks like you’re using the second argument of Instance.new(), a thread in 2016 explained why instead parenting the object separately after all properties have been set is a better idea performance wise.

 local value1, value2 = Instance.new("NumberValue"),  Instance.new("StringValue")

 value1.Parent = workspace
 value2.Parent = workspace

I tested your file and changed the value server-side, it detected the change and printed to output, can't seem to figure out what behavior you're labeling as a bug?

image

A function with no parameters is usually pointless in cases like these,

  local value = workspace:WaitForChild("Value")
  value.Changed:Connect(function(n)
        print("new value: ", n)
  end)

  wait(5)
  script:Clone().Parent = script.Parent

It prints each time the value gets changed (but infinitely clones due to the new script calling Clone() as well, which gets cloned later on too).

Instance.Changed is not deprecated.

I suspect strongly the issue was that you were changing values from the client, and so the changed values didn’t replicate nor did any change get detected on the server.


^ enter server-mode first, or just change the values from a server-script

You can still withdraw your report before it’s too late.

Thats probably it, I’ll withdraw the “bug” as soon as I can. It works on the console as the console runs it as local not server.

Again the script I’m working on has parameters for each function and for reasons I can not reveal much of the script. Rest assured there a reason why it’s there.

Never knew that, it’s only creating it once so it won’t affect me that much. I would consider the lines of code saved and by extention the clearness of the script to be a good enough reason to keep using it.

As stated before I’ve check it for syntax errors and and system is rigid with input only comming in from server scripts and not players. The value object is defined in script 1.

Thanks for pointing it out. I guess my brain was still in the era before filtering and client only changes.

1 Like