Local UI Script: Not Detecting MouseButton1Down or MouseButton1Up

:wave: Hello!

For a bit now, I’ve been trying to debug one of my local scripts. I’ve been unable to get it to detect the MouseButton1Down or MouseButton1Up events, and am almost 100% sure this is the issue. Here’s my code:

-- Services:
local RPS = game:GetService("ReplicatedStorage"):WaitForChild("ReplicatedStorage")
local TWS = game:GetService("TweenService")

-- Variables:
local OpenPromotionUI = RPS:WaitForChild("UIEvents"):WaitForChild("OpenPromotionUI")
local PlayerRejoin = RPS:WaitForChild("UIEvents"):WaitForChild("PlayerRejoin")

local Panel = script.Parent
local PanelBorder = Panel.Border
local PanelPos = Panel.Position

local TopBar = Panel.TopBar

local Title = TopBar.Title
local TitleBorder = Title.UIStroke

local Description = Panel.Description
local Reason = Panel.Reason

local DescriptionBorder = Description.UIStroke
local ReasonBorder = Reason.UIStroke

local CloseBTN = Panel.CloseBTN
local CloseBorder = CloseBTN.Border

local IsVisible = false

-- Functions:
local function createTween(object, goal, time)
	local tween = TWS:Create(object, TweenInfo.new(time), goal)
	tween:Play()
end

OpenPromotionUI.OnClientEvent:Connect(function(ReasonHere)
	IsVisible = true
	
	Panel.Position = PanelPos - UDim2.new(0,0,0.05,0)
	
	Description.Text = "Congratulations, ".. game.Players.LocalPlayer.Name.. ". You've recieved a promotion from a member of our Staff Team. To claim your new rank, use the rejoin button below."
	Reason.Text = "Reason: ".. ReasonHere
	
	wait(0.05)
	
	createTween(Panel, {BackgroundTransparency = 0.43}, 0.15)
	createTween(PanelBorder, {Transparency = 0}, 0.15)

	createTween(TopBar, {BackgroundTransparency = 0}, 0.15)
	
	createTween(Title, {TextTransparency = 0}, 0.15)
	createTween(Description, {TextTransparency = 0}, 0.15)
	createTween(Reason, {TextTransparency = 0}, 0.15)

	createTween(DescriptionBorder, {Transparency = 0}, 0.15)
	createTween(TitleBorder, {Transparency = 0}, 0.15)
	createTween(ReasonBorder, {Transparency = 0}, 0.15)

	createTween(CloseBTN, {TextTransparency = 0, BackgroundTransparency = 0}, 0.15)

	createTween(CloseBorder, {Transparency = 0}, 0.15)

	Panel:TweenPosition(PanelPos, nil, nil, 0.15, true)
end)

CloseBTN.MouseEnter:Connect(function()
	createTween(CloseBTN, {BackgroundColor3 = Color3.new(0.490196, 0.572549, 0.870588)}, 0.05)
	createTween(CloseBorder, {Color = Color3.new(0.490196, 0.572549, 0.870588)}, 0.05)
end)

CloseBTN.MouseLeave:Connect(function()
	createTween(CloseBTN, {BackgroundColor3 = Color3.new(0.564706, 0.658824, 1)}, 0.05)
	createTween(CloseBorder, {Color = Color3.new(0.439216, 0.509804, 0.776471)}, 0.05)
end)

CloseBTN.MouseButton1Down:Connect(function()
	warn("Detect")
	createTween(CloseBTN, {BackgroundColor3 = Color3.new(0.435294, 0.509804, 0.772549)}, 0.05)
	createTween(CloseBorder, {Color = Color3.new(0.435294, 0.509804, 0.772549)}, 0.05)
end)

CloseBTN.MouseButton1Up:Connect(function()
	createTween(CloseBTN, {BackgroundColor3 = Color3.new(0.564706, 0.658824, 1)}, 0.05)
	createTween(CloseBorder, {Color = Color3.new(0.439216, 0.509804, 0.776471)}, 0.05)
	
	PlayerRejoin:FireServer()
end)

When the player holds down click on the CloseBTN, or just normally clicks on it, neither functions play. There is no animation and no errors show up in output. The CloseBTN is a textbutton, meaning it couldn’t be the issue of it being an UI element that doesn’t accept MouseButton1Down / 1up. Any ideas on how I could fix this?

Make sure there isn’t another selectable/active UI element on top of it that’s blocking the user input for the close button. Also, make sure these properties are enabled for the button itself.

If the MouseEnter, MouseLeave, MouseButton1Down events are not firing then the above is most likely the case.

3 Likes

The button does have Active, and Selectable properties enabled and I’m 100% sure there’s no other UI elements blocking it. It’s detecting Mouse Enter and Mouse Leave, just not Button1Down or Up.

1 Like

I tinkered around for a while, and finally got it working. I’m not even sure what the issue was, if it was something to do with UI properties or code, but it works fine now.

Here’s my code:

-- Services:
local RPS = game:GetService("ReplicatedStorage"):WaitForChild("ReplicatedStorage")
local TWS = game:GetService("TweenService")

-- Variables:
local OpenPromotionUI = RPS:WaitForChild("UIEvents"):WaitForChild("OpenPromotionUI")
local PlayerRejoin = RPS:WaitForChild("UIEvents"):WaitForChild("PlayerRejoin")

local Panel = script.Parent
local PanelBorder = Panel.Border
local PanelPos = Panel.Position

local TopBar = Panel.TopBar

local Title = TopBar.Title
local TitleBorder = Title.UIStroke

local Description = Panel.Description
local Reason = Panel.Reason

local DescriptionBorder = Description.UIStroke
local ReasonBorder = Reason.UIStroke

local CloseBTN = script.Parent.CloseBTN
local CloseBorder = CloseBTN.Border

-- Functions:
local function createTween(object, goal, time)
	local tween = TWS:Create(object, TweenInfo.new(time), goal)
	tween:Play()
end

OpenPromotionUI.OnClientEvent:Connect(function(ReasonHere)	
	Panel.Position = PanelPos - UDim2.new(0,0,0.05,0)
	
	Description.Text = "Congratulations, ".. game.Players.LocalPlayer.Name.. ". You've recieved a promotion from a member of our Staff Team. To claim your new rank, use the rejoin button below."
	Reason.Text = "Reason: ".. ReasonHere
		
	createTween(Panel, {BackgroundTransparency = 0.43}, 0.15)
	createTween(PanelBorder, {Transparency = 0}, 0.15)

	createTween(TopBar, {BackgroundTransparency = 0}, 0.15)
	
	createTween(Title, {TextTransparency = 0}, 0.15)
	createTween(Description, {TextTransparency = 0}, 0.15)
	createTween(Reason, {TextTransparency = 0}, 0.15)

	createTween(DescriptionBorder, {Transparency = 0}, 0.15)
	createTween(TitleBorder, {Transparency = 0}, 0.15)
	createTween(ReasonBorder, {Transparency = 0}, 0.15)

	createTween(CloseBTN, {TextTransparency = 0, BackgroundTransparency = 0}, 0.15)

	createTween(CloseBorder, {Transparency = 0}, 0.15)

	Panel:TweenPosition(PanelPos, nil, nil, 0.15, true)
		
	script.Parent.CloseBTN.MouseEnter:Connect(function()
		createTween(CloseBTN, {BackgroundColor3 = Color3.new(0.490196, 0.572549, 0.870588)}, 0.05)
		createTween(CloseBorder, {Color = Color3.new(0.490196, 0.572549, 0.870588)}, 0.05)
	end)

	script.Parent.CloseBTN.MouseLeave:Connect(function()
		createTween(CloseBTN, {BackgroundColor3 = Color3.new(0.564706, 0.658824, 1)}, 0.05)
		createTween(CloseBorder, {Color = Color3.new(0.439216, 0.509804, 0.776471)}, 0.05)
	end)

	script.Parent.CloseBTN.MouseButton1Down:Connect(function()
		createTween(CloseBTN, {BackgroundColor3 = Color3.new(0.435294, 0.509804, 0.772549)}, 0.05)
		createTween(CloseBorder, {Color = Color3.new(0.435294, 0.509804, 0.772549)}, 0.05)
	end)

	script.Parent.CloseBTN.MouseButton1Up:Connect(function()
		createTween(CloseBTN, {BackgroundColor3 = Color3.new(0.564706, 0.658824, 1)}, 0.05)
		createTween(CloseBorder, {Color = Color3.new(0.439216, 0.509804, 0.776471)}, 0.05)

		wait(0.05)

		PlayerRejoin:FireServer()
	end)
end)


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