Checking if one of many values changes

So i have more than 1 value inside a folder, and i want to check if one of them changes.
what im confused about is that i cant just use “value.Changed” because i dont know which value changed.

i though of using for loops but cant find where to use them
this might or might not help you understand my question:

local folder = game.ReplicatedStorage.Folder

-- "the value that changed inside that folder".Changed:Connect(function()
--      print(the value that changed inside that folder.."Changed")
--end)

Thanks in advance!

3 Likes
local folder = game.ReplicatedStorage.Folder
for _, value in ipairs(folder:GetChildren()) do
value.Changed:Connect(function()
print(value.Name)
end)
end

Within the function ‘value’ would be the value (instance) that was changed.

i had to add a while true do for that to work, but i thought it had limits? like it could stop after a while

Is this a localscript or a serverscript?

it’s a server script, i cant change it to a local one

Use:

repeat
--code
until

So it will stop when something is triggered.

Long and behold, the script that should solve this:

local function SomeFunction(value)
print(value.Name)
end
local folder = game.ReplicatedStorage.Folder
for _, value in ipairs(folder:GetChildren()) do
value.Changed:Connect(function()
SomeFunction(value)
end)
end
folder.ChildAdded:Connect(function(value)
value.Changed:Connect(function()
SomeFunction(value)
end)
end)

SomeFunction’s value is the value that was changed.

2 Likes

im not instancing the values tho, they’re already in the folder does it still work that way?

it should keep going forever tho, there’s no “until”

Yes, that what the for loop is for, it should pick up already created values.

i will try that and let you know, thanks a lot!

If it doesn’t work try adding a task.wait(1) in front of the piece of code as it may be an error with the values not existing when the for loop was called.

it works perfectly fine, the value only changes when the player changes it, so there shouldn’t be any errors, as the values already exist when the player does that.

1 Like