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

Update the :GetChildren() ???

Asked by 3 years ago

How can i update the :GetChildren() ?? already try with childadded and childremoved like this one but when i try to add like a number value and change the value it wont print

local Checker = ServerStorage:WaitForChild("PlayerItem"):FindFirstChild(plr.Name):GetChildren()

ServerStorage:WaitForChild("PlayerItem"):FindFirstChild(plr.Name).ChildAdded:Connect(function(child)
    Checker = ServerStorage:WaitForChild("PlayerItem"):FindFirstChild(plr.Name):GetChildren()

end)

ServerStorage:WaitForChild("PlayerItem"):FindFirstChild(plr.Name).ChildRemoved:Connect(function(child)
    Checker = ServerStorage:WaitForChild("PlayerItem"):FindFirstChild(plr.Name):GetChildren()
    end)

for i,v in pairs (Checker) do
    if v:IsA('NumberValue') then
        v.Changed:Connect(function()
            local Names = v.Name
            local Amount = v.Value
            print(Names, Amount)
        end)
    end
end

1 answer

Log in to vote
0
Answered by 3 years ago

You should make a ChildAdded function, and loop through the objects that are already there and establish a ChildAddedEvent in the folder.


local function onChildAdded(child) if child:IsA("NumberValue") then child.Changed:Connect(function(prop) local Names = child.Name local Amount = child.Value print(Names, Amount) end) end end ServerStorage:WaitForChild("PlayerItem"):FindFirstChild(plr.Name).ChildAdded:Connect(onChildAdded) -- establish a .ChildAdded Event. for _, child in pairs(ServerStorage.PlayerItem:FindFirstChild(plr.Name):GetChildren()) do -- loop through the children alredy there! onChildAdded(child) end

If this works, please mark this as an answer

Ad

Answer this question