So with one of my recent projects I've decided to work on a card game. Data of each specific card is stored in a folder pertaining to that card such as stats, name, text, etc. But one issue I've been thinking about is what to do in the situation of data manipulation, for example, buffing a unit. I've looked around but I haven't found any solutions whatsoever.
Will I have to setup a listener for each individual object, one for health, one for attack, etc, or is there some way I could listen to all of the Value objects within the folder at once to see if any of them has changed?
I've read the comments and based on what you said of listening for changes in multiple objects at once, a loop is definitely what you need.
So one of the normal harder solutions would just to be manually connecting all the events like so:
card.attack.Changed:Connect(function() end) card.defence.Changed:Connect(function() end) card.speed.Changed:Connect(function() end) -- and so on
for an easier way to do this is to iterate through using a loop!
for _, stat in pairs(card:GetChildren()) do stat.Changed:Connect(function() -- this will connect all the stats to a listener end) end
and if want specific ones you can do:
for _, stat in pairs(card:GetChildren()) do if stat.Name ~= "name" and stat.Name ~= "Text" then -- name and text will not be connected stat.Changed:Connect(function() -- this will connect all the stats to a listener end) end end
Now obviously this is a visual to help you understand what you can do so copy pasting this will not work.
PS: Remember not to connect the listeners to the cards in the storage rooms and make sure to connect them to the cards in game. This many be an common error for some people.
Good luck
EDIT: (Global Listener for workspace)
for _, instance in pairs(workspace:GetDescendants()) do if instance:IsA("IntValue") or instance:IsA("StringValue") or instance:IsA("NumberValue") then -- add on here of what you want to listen to instance.Changed:Connect(function() print("Test") -- make sure this script is server script in serverscriptservice end end end workspace.DescendantAdded:Connect(function(instance) -- whenever something is added to workspace if instance:IsA("IntValue") or instance:IsA("StringValue") or instance:IsA("NumberValue") then -- add on here of what you want to listen to instance.Changed:Connect(function() print("Test") -- make sure this script is server script in serverscriptservice end end end)