Connecting Multiple Buttons To One Script

Hey so I’m trying to connect multiple ImageButtons to one local script. I want the script to detect when “EnterDown” is clicked (the one selected in the pic)
image

However, I get this error

MouseButtton1Click is not a valid member of ImageButton "Players.Play_MazeOfHeck.PlayerGui.GUI.Tutorial.Welcome.EnterDown" - Client - Tutorial:28

How can I prevent it from thinking MouseButton1Click is a child of ImageButton?

Part of Script:

local Tutorial = script.Parent
local WelcomeDown = Tutorial:FindFirstChild("Welcome"):FindFirstChild("EnterDown")
local Habitat = Tutorial:FindFirstChild("Habitat")
local HabitatDown = Habitat:FindFirstChild("EnterDown")
local Hatchery = Tutorial:FindFirstChild("Hatchery")
local HatcheryDown = Hatchery:FindFirstChild("EnterDown")
local FoodFarm = Tutorial:FindFirstChild("FoodFarm")
local FoodFarmDown = FoodFarm:FindFirstChild("EnterDown")
local QuestBuilding = Tutorial:FindFirstChild("QuestBuilding")
local QuestBuildingDown = QuestBuilding:FindFirstChild("EnterDown")
local EggBuilding = Tutorial:FindFirstChild("EggBuilding")
local EggBuildingDown = EggBuilding:FindFirstChild("EnterDown")

WelcomeDown.MouseButtton1Click:Connect(function()
	print("was clicked")
	beam.Attachment0 = player.Character:FindFirstChild("HumanoidRootPart"):WaitForChild("TutorialGPSAttachment")
	beam.Attachment1 = Islands:WaitForChild(PlotNumber, 20).StarterIsland.WaterHabitat:FindFirstChild("Sand").Attachment
	beam.Parent = player.Character:FindFirstChid("HumanoidRootPart")
	wait(5)
	Habitat.Visible = true
end)

HabitatDown.MouseButton1Click:Connect(function()
	beam.Attachment1 = Islands:WaitForChild(PlotNumber, 20).StarterIsland.Hatchery.EggStand1.Stand.Attachment
	wait(5)
	Hatchery.Visible = true
end)

Thank you!

You made a mistake here:

You accidentally spelt “Button” wrong, and I don’t recommend using MouseButton1Click, because it sometimes doesn’t work.

Try this, instead:

local Tutorial = script.Parent
local WelcomeDown = Tutorial:FindFirstChild("Welcome"):FindFirstChild("EnterDown")
local Habitat = Tutorial:FindFirstChild("Habitat")
local HabitatDown = Habitat:FindFirstChild("EnterDown")
local Hatchery = Tutorial:FindFirstChild("Hatchery")
local HatcheryDown = Hatchery:FindFirstChild("EnterDown")
local FoodFarm = Tutorial:FindFirstChild("FoodFarm")
local FoodFarmDown = FoodFarm:FindFirstChild("EnterDown")
local QuestBuilding = Tutorial:FindFirstChild("QuestBuilding")
local QuestBuildingDown = QuestBuilding:FindFirstChild("EnterDown")
local EggBuilding = Tutorial:FindFirstChild("EggBuilding")
local EggBuildingDown = EggBuilding:FindFirstChild("EnterDown")

WelcomeDown.MouseButton1Down:Connect(function()
	print("was clicked")
	beam.Attachment0 = player.Character:FindFirstChild("HumanoidRootPart"):WaitForChild("TutorialGPSAttachment")
	beam.Attachment1 = Islands:WaitForChild(PlotNumber, 20).StarterIsland.WaterHabitat:FindFirstChild("Sand").Attachment
	beam.Parent = player.Character:FindFirstChid("HumanoidRootPart")
	wait(5)
	Habitat.Visible = true
end)

HabitatDown.MouseButton1Down:Connect(function()
	beam.Attachment1 = Islands:WaitForChild(PlotNumber, 20).StarterIsland.Hatchery.EggStand1.Stand.Attachment
	wait(5)
	Hatchery.Visible = true
end)
1 Like