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

Does" for index, child in pairs() do" Not work anymore?

Hey guys, this broken script has been frustrating me because It used to work perfectly and now it only works in edit play (testing) mode. I can usually figure out what part of the script is messed up if a script isn't working by removing chunks of code and seeing what happens, or by taking other troubleshooting steps, and I did that here. What I can't figure out though, is that it seems that the problem is the "for index, child in pairs(SBUTTONS) do" part of the code... and i can't find anything wrong with it.

Context Info: -This IS a local script -Script is inside a "frameception" (frame inside a frame inside a frame...) -Filtering Enabled is NOT on

Any help or suggestions would be appreciated. Thanks!

local player = game.Players.LocalPlayer

local BUTTON = script.Parent
local FRAME = BUTTON.Parent.Parent.ScrollingFrame2


FRAME.Visible = false

--------------------------------------------------


function onMouseButton1Down(mouse)
	local SBUTTONS = BUTTON.Parent.Parent:GetChildren()
	local NAME = BUTTON.Name
	print("clicked2")
	FRAME.Visible = true
	
	for index, child in pairs(SBUTTONS) do
		if child.Name ~= NAME and child.Name ~= "SelectBar" 
			then child.Visible = false
			
		end
		
	end
end

BUTTON.MouseButton1Down:connect(onMouseButton1Down)

8 comments

0

Error?

0

Well in play mode when I open up the dev console it doesn't have any errors that I think are relevant

0

Also, I don't think it is recognizing its being clicked because I put in the "print("clicked2") to test it and it never showed up in the dev console

0

Well what errors do you have? Try checking the output, I don't think developer console may work as in intended in Play Solo mode, then again I've never tried. The error should look something like game.Players.Player.PlayerGui.Gui.Script:123 ... something in red text with blue text following.

0

When I'm in studio and I click the test play button the script works perfectly fine, but its only when I play the game normally that it doesn't work. Here is an example of an error that shows up in the Dev console when I'm actually playing the game. ((red) NameFrame is not a valid member of Frame) ((blue) Script 'Players.GWolflover.PlayerGui.CraftGui.Bolt.Craft.TextButton.Cscript' , Line 2)

0

That is just one of many almost identical errors. The other ones are the same but for the other items in my crafting menu, and I'm not sure if these errors are related to the problem that this post is about but they could be. The scripts these errors are referring to are within Frames that are descendants of the buttons that contain the script that this post is about. Sorry this is so complex, I'

0

Also, ive looked at these errors extensively and basically they are telling me that a Frame's child that I refer to doesn't exist and Ive quadruple checked and I referred to it exactly right (in Cscript which is the script the errors refer to) so I don't know whats wrong.

0

Try replacing index with i

1 answer

Try replacing the 'index' with an 'i'. Like this:

for i, child in pairs(something) do

end

3 comments

0

Dang, I was hoping that would work but it doesn't. I'm still trying everything I can think of to troubleshoot so I can find what the problem is but all i've found out is that I got the script in the first button to work (there are four buttons that are the same except their names) but I copied and pasted the script into the second button EXACTLY except for the name and it STILL doesn't recognize

0

that it's being clicked. I even tried leaving ONLY a print() inside the function so that I would know if it recognizes when it's clicked but it doesn't. What could possibly cause that if the scripts and buttons are identical except for the names?

0

This is such a weird error. I've never gotten one of these. Maybe try waiting a couple seconds before running the script.

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