My function in the for i,v prints out random numbers

It should, ve printed the child’s name but as I said it prints out random numbers which as I guess are how close is the mouse’s click to the corner
And I tried putting .name after but still the same.

here is the code:

local airs = script.Parent.ScrollingFrame:GetChildren()

for I, v in pairs(airs) do
	v.MouseButton1Up:Connect(function(selected1)
		print(selected1)
	end)
end

Small tip: you should make an if statement checking which of the children are TextButtons (if that’s what you are trying to detect), since your code could possibly throw an error if a child is not a TextButton.

Your fixed code:

local airs = script.Parent.ScrollingFrame:GetChildren()

for I, v in pairs(airs) do
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			print(v.Name) -- prints the TextButtons name
		end)
	end
end


As you can see here the first parameter of MouseButton1Up is the X and second is Y

https://create.roblox.com/docs/reference/engine/classes/GuiButton

Hope this helps!

1 Like

I just pasted the code but it still does not work. This time it is not printing anything.

Any errors in the output? Also, what/which instances are you trying to get under the ScrollingFrame? Maybe try MouseButton1Click instead of Activated, as Activated only runs in a LocalScript. I have edited the code in my post above.

I fixed it by replacing Activated with MouseButton1Click. Thanks again.

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