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)
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.
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.
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)