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)
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.
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.
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.