Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a function to check if multiple values have changed?

Hi, I would like to know if there was a function to check whether a folder's children have changed(They are IntValues). I know how to check them individually, for example:

workspace.Value.Changed:Connect(function()
	print("changed!")
end)

but I want it so that if one of the folder's children changes, a function will do something and if the other children change, the same function will execute.

Please Help!

2 comments

0

The closest thing Roblox natively has is Instance.ChildAdded or .ChildRemoved. For more information, look here: https://developer.roblox.com/api-reference/class/Instance

0

Otherwise, you would have to loop through the folder's contents and create a .Changed event for each one. I would create a single BindableEvent that you can fire. See my answer.

2 answers

✓ Accepted answer

You can try using an in pairs loop with a changed event like this:

for i,v in pairs (game.Workspace:GetChildren()) do
	if v:IsA('IntValue') then
		v.Value.Changed:Connect(function()
			-- Insert code here
		end)
	end
end

The for loop will go through all the children in the workspace, then the if statement will check to see if the child is an intvalue, then it will see if the intvalue's value has changed.

If you do not like this method, you can always check for changes in the descendants of the workspace.

The easiest way to accomplish this would be a BindableEvent, like so:

local event = Instance.new("BindableEvent", game.ReplicatedStorage)

event.Event:connect(function()
	print("Changed!")
end)

for _,v in pairs(folder:GetChildren()) do
	v.Changed:connect(function()
		event:Fire()
	end)
end)

1 comment

0

By binding all the events to one Bindable event, it makes it easier to script. https://developer.roblox.com/api-reference/class/BindableEvent

This discussion is preserved as it was. New answers, comments, and votes are closed.