Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a GetChildrenWhichEquals?

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.

1 comment

0

More like a FindValueWhichEquals

1 answer

✓ Accepted answer

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)

5 comments

0

has to strictly equal the number though. you might have some issues with floating points

0

what is the name of the values that equal number if i want to change them?

0

also what name do i need to change? number?

0

nvermind im sstupid sometime

0

i gave example

This discussion is preserved as it was. New answers, comments, and votes are closed.