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

How to make a GetChildrenWhichEquals?

Asked by 4 years ago
Edited 4 years ago

What i want is that when i click a gui button (for example), its check in my leaderstats and look in all the values if they = 1 and set them to 0 if they = 1. Its like a "GetChildrenWhichEquals". Im not really good to explain but i think you understands.

0
More like a FindValueWhichEquals scorpion981 27 — 4y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago

You can write a function for it: GetChildrenWhichEquals returns a table with all the value objects that equal number

function GetChildrenWhichEquals(parent, number)
    local childrenWithValue = {}

    --go through all the parents children:
    for _, child in pairs(parent:GetChildren()) do

        -- if child is a value object then
        if  child.ClassName:sub(-5) == "Value" then
            --check if the child's value equals value specified
            if child.Value == number then
                table.insert(childrenWithValue, number)
            end
        end

    end

    return childrenWithValue 
end

local leaderstats = game.Players.LocalPlayer.leaderstats

local children = GetChildrenWhichEquals(leaderstats, 2)
0
has to strictly equal the number though. you might have some issues with floating points royaltoe 5144 — 4y
0
what is the name of the values that equal number if i want to change them? scorpion981 27 — 4y
0
also what name do i need to change? number? scorpion981 27 — 4y
0
nvermind im sstupid sometime scorpion981 27 — 4y
0
i gave example royaltoe 5144 — 4y
Ad

Answer this question