MouseButton1Click not detected

I am trying to maketwo buttons visible when other button gets clicked, but mousebutton1click is not detected. does anyone know how to fix it?

local landTerraformationButton = game.StarterGui.ScreenGui:WaitForChild("TerraformButton");
local upButton = game.StarterGui.ScreenGui:WaitForChild("UpTerraform");
local downButton = game.StarterGui.ScreenGui:WaitForChild("DownTerraform");


landTerraformationButton.MouseButton1Click:Connect(function()
	print("ok");
	upButton.Visible = not upButton.Visible
	downButton.Visible = not downButton.Visible
end)

local script is in screengui

You’re detecting the MouseButton1Click in StarterGui, which are not the same as the one in player.PlayerGui.
You need to find the player and use it from there

local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui
local landTerraformationButton =gui.ScreenGui:WaitForChild("TerraformButton");
local upButton = gui.ScreenGui:WaitForChild("UpTerraform");
local downButton =gui.ScreenGui:WaitForChild("DownTerraform");


landTerraformationButton.MouseButton1Click:Connect(function()
	print("ok");
	upButton.Visible = not upButton.Visible
	downButton.Visible = not downButton.Visible
end)

First line make game.Player.LocalPlayer.PlayerGui… insteat game.StarteGui

Or if the script is in your button make on line 6: script.Parent.MouseButton1Click:Connect(function)

PlayerGui | Documentation - Roblox Creator Hub

Would probably add a WaitForChild here

1 Like

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