I want a function to happen when any value in a folder is changed how would I check for this using .changed
You could try something like this
local Folder = folder --Your folder here
for i, v in ipairs(Folder:GetDescendants()) do
v.Changed:Connect(function()
--What you want to do whenever that value is changed
end
end
Did this help you enough? If not, please let me know
If you want to know what value is changed exactly, you may try this:
for i, v in ipairs(Folder:GetDescendants()) do
v:GetPropertyChangedSignal("whateverpropertyyoudliketosee"):Connect(function()
--What you want to do whenever that property is changed
end
end
Folder shows that you can check for Folder.Instance.Changed.
If you want to find out which property is changed then use Instance:GetPropertyChangedSignal
local folder = workspace.Folder --Example folder.
for _, valueInstance in ipairs(folder:GetChildren()) do
if valueInstance:IsA("ValueBase") then
valueInstance.Changed:Connect(function(newValue)
print(newValue)
end)
end
end
If you want to check if any values in a folder have changed, you can use a for loop to loop through the folder and grab all the children:
for i, v in ipairs(workspace.FolderOfValues:GetChildren()) do
if v:IsA("IntValue") or v:IsA("StringValue") then
v.Changed:Connect(function(value)
print(v.Name.."'s value has changed to "..value)
end)
end
end
We use an if statement to check if v
is an IntValue or StringValue, and if so, we check for when v’s value has changed using the .Changed event.
I should have thought of that but why did you use GetDescendants instead of GetChildren?
The descendants function also gets the children of the children, so basically everything parented in that folder.
Just check if the instance inherits from the ValueBase
class (the base class for those instances).
Yes you can do that, the only reason I didn’t do that was because I can’t concatenate a BoolValue without using tostring(), and I didn’t want to have to add in more code than necessary.
The issue is, that when a new instance is added to that folder the for loop doesn’t count it