Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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!

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 BreadyToCrumble 121 — 5y
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. BreadyToCrumble 121 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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.

Ad
Log in to vote
0
Answered by 5 years ago

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)
0
By binding all the events to one Bindable event, it makes it easier to script. https://developer.roblox.com/api-reference/class/BindableEvent BreadyToCrumble 121 — 5y

Answer this question