✓ Accepted answer
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)
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()
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
stat.Changed:Connect(function()
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
instance.Changed:Connect(function()
print("Test")
end
end
end
workspace.DescendantAdded:Connect(function(instance)
if instance:IsA("IntValue") or instance:IsA("StringValue") or instance:IsA("NumberValue") then
instance.Changed:Connect(function()
print("Test")
end
end
end)
7 comments
Not really sure what you are talking about but i think what you are looking for is a for loop.
No. A for loop is definitely not going to help. I'm trying to listen for changes in properties of several objects at once. For example, ObjectValue.Changed:Connect etc. But instead of say, just the one objectvalue, I could listen for five of them on the same listener.
Aren't the values of cards static? Why, then, would you need to listen to changes? Wouldn't there be no changes?
In the post above I specifically listed that there would be changes such as buffing a unit. If you're unfamiliar with the term, an example would be giving the card an extra 3 attack or health.
That doesn't mean that you need to listen to changes... wouldn't you just access those values when you play the card?
I would need to actually update the visual of the card itself for when said changes take place so I don't just randomly have something with 1 attack doing 4 damage because it's attack got buffed but wasn't shown on the card.
In that case, I'd create a base card class and loop through every card to intialize it. So yes, a generic for loop is the way to go here (even if you don't take the OOP approach).