I wanna make it do something when player clicks

for _, button in pairs(script.Parent.Frames:GetDescendants()) do
	if button:IsA("GuiButton") then
		button.MouseButton1Click:Connect(function()
			if ViewPort.Visible == true then
				ViewPort.Visible = false
			elseif ViewPort.Visible == false then
				ViewPort.Visible = true	
			end
		end)
	end
end

I’m basically trying to make it so if the player clicks a certain frame it changes a text depend on the frame number

image
Also i wanna make it count how many frames we have
Help is appreciated :slightly_smiling_face:

MouseButton1Click isn’t an event tied to Frames. You would have to use a GuiButton | Roblox Creator Documentation. This is a class that encompasses ImageButtons and TextButtons.

I wanna make it so it changes a text depends on the frame number

You’re trying to click on the frame, not the button inside. You can get the button by using the Index of the in pairs, which should get the number right. You could also leave the buttons name as just “Button” and name the frame as the number instead.

You also are using .MouseButton1Click, which is not mobile friendly, and has other random issues. Use .Activated instead, as it supports mobile automatically and does a better job.

for i, v in pairs(script.Parent.Frames:GetChildren()) do
	if v[i]:IsA("GuiButton") then
		v[i].Activated:Connect(function()
			if ViewPort.Visible == true then
				ViewPort.Visible = false
			elseif ViewPort.Visible == false then
				ViewPort.Visible = true	
			end
		end)
	end
end

You can use # and :GetChildren() to count how many frames you have.

local frames = script.Parent.Frames
local frame_count = #frames:GetChildren()

To get the text to change depending on the frame number, just use a loop and use the iterator variable i.

1 Like

Im trying to use the loop but i just keep using it in-correct i didnt sleep for so long so my mind is kinda buggy rightnow