Anyone know why this button does not work when it gets clicked?

So when i click this button for some reason it will not run the script/event I put in. I am getting no errors so not sure why this is not working. I have used the exact same script before as well to open the UI just changed the position to move to.

local button = script.Parent

local plr = game.Players.LocalPlayer

local Menu = plr.PlayerGui:WaitForChild("ButtonsAndMenus").Codes.CodeMenu.Frame



button.MouseButton1Click:Connect(function()
	print("Button clicked!")
	local play = Menu:TweenPosition(
		UDim2.new(-1.018, 0, 0, 0)
	)
end)

is it in a local script
is it printing “Button clicked!”
is the script inside the button

It is a local script, it is not printing button clicked that is why I know the event is not runing and the script is inside the button. This is why I am confused on why it is not working as I have done the exact same before and all the things I can think off does not work.

image

Because it appears that the Menu you’re adjusting the position of is in the same ScreenGui where the button is being activated, you could adjust the Menu variable to reference it much more intuitively:

local CloseButton = script.Parent
local Menu = CloseButton.Parent

Otherwise, I don’t see much of a reason why it wouldn’t be working if no errors are occurring.

Ok I will have a play around with my script. While you are here got any idea why this script is giving me an error?

local submit = script.Parent

submit.MouseButton1Click:Connect(function(plr)
	local CodeSubmited = plr.PlayerGui:WaitForChild("ButtonsAndMenus").Codes.CodeMenu.Frame.EnterCodeHere.Text

	print(CodeSubmited)
end)

image

When the MouseButton1Click event is connected to a function, the player that clicked it is not sent through as an argument. Since it’s in a LocalScript, the LocalPlayer can be referenced to access the player.


I initially thought what you presented in the OP wouldn’t work because you’re storing the TweenPosition inside of a variable and not calling it, but I tested it out and it works differently from utilizing the Create method of the TweenService (where you’d need to call Play() on the Tween that was created).

I tested the following inside of a blank place and it worked fine, so it may be coming down to the button that you’re referencing since you mentioned in one of the replies that nothing was printing.

local button = script.Parent
local ImageLabel = button.Parent

button.Activated:Connect(function()
	print("Button clicked!")
	
	local Tween = ImageLabel:TweenPosition(
		UDim2.new(-1.018, 0, 0, 0)
	)
	
	if Tween then
		print("The tween for the ImageLabel 'Frame' worked")
	else
		warn("The tween for the ImageLabel 'Frame' did not work")
	end
end)

Could it be because the CloseButton is covered the TextButton? Try to make the TextButton covered CloseButton.

If any GUI such as: ImgeLabel, TextButton, ScreenGui etc is inside of a folder clicking might not work.