Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I check for a value change in multiple items?

Asked by 3 years ago

Hi,

I'm currently scripting an shop-inventory system that is going to be displayed with a GUI. The items to be displayed are in the ReplicatedStorage, and have multiple value instances (that are the same for every items) as children that are used as info for text. For example: Value Name of item A in the ReplicatedStorage will be used to change the text of a TextLabel called ItemName in the StarterGui.

I have two values, Quantity and Rarity. Every time Quantity changes, I want an average of the previous Rarity value and a new value to be calculated and I want that average as the new value for Rarity.

But I don't know how I can do this. Putting scripts as the value's children was my option until I found out scripts doesn't work in ReplicatedStorage. Then I moved on to creating a script from somewhere else, but because the Quantity and Rarity values are all children of all of the items, I don't know how to check when an item has its Quantity value changed and then reference it. Additionally, because there are 30-40 items (that will be added), checking it manually using .Changed isn't really efficient.

So is there anything I can do? Or do I have to rework my system? I'm still pretty new to scripting, so any help is appreciated!

Thank you!

TLDR: How do I check for changes and reference a value that is in multiple items?

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I believe :GetPropertyChangedSignal() is what you need I don't know how your game works so here's roughly what you should do

Quantity:GetPropertyChangedSignal("Value"):Connect(function()
    if Quantity.Value < 15 then Rarity.Value == "5star" 
    elseif Quantity.Value > 15 and Quantity.Value < 30 then Rarity.Value == "4star" end
    --et cetera
end)

You can use this same :GetPropertyChangedSignal() to change the text on your GUIs as well

EDIT:

Use a for in pairs loop to loop through each quantity.

for i, v in pairs(Items:GetChildren()) do
    wait() --optional
    v.Item.Quantity:GetPropertyChangedSignal("Value"):Connect(function()
        --stuff
    end)
end
0
I did try that, but I haven't got it work for situations when multiple items's Quantity value changed. If Item A's Quantity changed to 13 and Item B's Quantity changed to 15 at the same time, how can I change each item's Rarity value? TrueMU25v2 2 — 3y
0
Alright I edited my answer Gmorcad12345 434 — 3y
Ad

Answer this question