How to use :GetChildren() in this situation, please help

  1. What do you want to achieve? Keep it simple and clear!
    How would I get children inside “Spellbook”, then get each “CD”, and find the “inputkey” frame, and get its text for every single “CD” in there, my point of doing that is so i can use .Changed to detect when its changed so i can fire a remote and do what i want on the server

  2. What is the issue? Include screenshots / videos if possible!
    Don’t know how to exactly do this, i looked through devforum but didn’t find much.

I’m not quite sure with what you mean with the ‘InputKey’ Frame, but I can show you an example of how the :GetChildren() function would be set up.
Excuse the code, I am on phone.

local spellBook = <path to spellbook>
local function SpellBookInstances()
   local instances = spellBook:GetChildren() --variable that now contains every child of spellbook
   for i, v in instances do --repeat for every child in instances
      print(v.KeyFrame)
      print(v.CD)
   end
end

SpellBookInstances() --run the command

Guessing that the instances in the Spellbook have a KeyFrame and CD property, it will print in the output console per each spell inside of the spellbook.

sorry, i didnt show you a screenshot of the explorer, it looks like this:
image

local CD_Table = {}
local Spells = ... -- enter here the poisition of spells scrollingframe

local function find_CD_on_table(item)
   for _, a in pairs(CD_Table) do
      if a.Item == item then
         return a
      end
   end
   return nil
end

for _, a in pairs(Spells:GetChildren()) do
   if a.Name == "CD" then

      table.insert(CD_table, {
         Item = a,
         Text = a.inputKey.container.Text,
      })

      a.inputKey.container.Changed:Connect(function()
         -- you can put here the remote you we're talking about
         -- you can also remove the table stuff but i just added them in case you need 
         local get = find_CD_on_table(a)
         if not get then return end
         get.Text = a.inputKey.container.Textthem
      end)

   end
end
1 Like

It changes when focusing on hitbox, it changed when typing the letter AND when pressing Enter, how would i just fire the event when a player presses Enter?

local CD_Table = {}
local Spells = ... -- enter here the poisition of spells scrollingframe

local function find_CD_on_table(item)
	for _, a in pairs(CD_Table) do
		if a.Item == item then
			return a
		end
	end
	return nil
end

for _, a in pairs(Spells:GetChildren()) do
	if a.Name == "CD" then

		table.insert(CD_Table, {
			Item = a,
			Text = a.inputKey.container.Text,
		})
		
		a.inputKey.container.ReturnPressedFromOnScreenKeyboard:Connect(function()
			local get = find_CD_on_table(a)
			if not get then return end
			get.Text = a.inputKey.container.Textthem
		end)

	end
end
1 Like

why place this in a table, cant u just do get children and thats it? i dont see a point in making cd_Table. can you maybe explain it please?

If you ever need it, I added it. Just how I like coding my stuff.

i didnt quite understand what you mean here, can you explain why would using tables like you did be better?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.