Getting buttons issues

Does anyone know what is wrong with my local script? Why is it not working properly?

image

image

local buttons = {script.Parent.Parent.GameMap:GetChildren()}
local gameMap = script.Parent.Parent.GameMap

script.Parent.MouseButton1Click:Connect(function()
gameMap.Visible = true
end)

buttons.Location1.MouseButton1Click:Connect(function()
print('location 1')
gameMap.Visible = false
end)

buttons.Location2.MouseButton1Click:Connect(function()
print('location 2')
gameMap.Visible = false
end)

buttons.Location3.MouseButton1Click:Connect(function()
print('location 3')
gameMap.Visible = false
end)

The :GetChildren() function returns a table that you can index with number values. (See here more information). You also can get rid of the curly brackets around it and try using .Activated unless you have your own reason for using .MouseButton1Click. Try this instead:

local gameMap = script.Parent.Parent.GameMap
local buttons = gameMap:GetChildren()

for _, button in ipairs(buttons) do
	button.Activated:Connect(function()
		print(button.Name)
		gameMap.Visible = false
	end)
end
1 Like

Thank you! but I try to open the map with the open map button and it doesn’t work for me, by any chance do you know what is wrong?

local openMapButton = script.Parent

script.Parent.MouseButton1Click:Connect(function()
   openMapButton.Visible = true
end)

Sure, I believe your problem is that you are setting the visibility of the button you’re clicking on rather than image of the game map.

image

I would like to press the button open map and that the image becomes visible, then if I press a locationbutton then the image and its childrens go visible false

Here you are setting the visiblity of the button itself. I assume you want to do gameMap.Visible = true

Thanks brother! I have been able to solve it :smiley:

local gameMap = script.Parent.Parent:WaitForChild("GameMap")
local buttons = gameMap:GetChildren()

script.Parent.MouseButton1Click:Connect(function()
	gameMap.Visible = true
end)

for i, v in pairs(buttons) do
	v.MouseButton1Click:Connect(function()
		print("Location "..i)
		gameMap.Visible = false
	end)
end

Is this the logic you’re looking for?