Hi,
Im trying to make something tween. How do I make it so that the first click will:
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0.07, 0, 0.276, 0),"Out", "Sine",1)
end)
and the second time you click it goes back to where it was before.
If it’s hard to understand then well, what im saying is, when you click a button it will make “MainFrame” tween. Then when you click the button again it goes back. So its like an open and close button.
From,
File
Create a Bool Variable that detects if the Button has been opened or not?
local Opened = false
local Button = script.Parent
Button.MouseButton1Down:Connect(function()
if Opened == true then
Opened = false
--Tween your Button here when you want to close it
elseif Opened == false then
Opened = true
--Tween your Button here when you want to open it
end
end)
1 Like
I would have never thought of that. Thanks!
I also have a question @JackscarIitt.
why is it
instead of
if opened == false then
Opened = true
since the statement starts at false.
I just did it at a random order, I mean you can change it however you’d like if you wanna start the false
check first
It doesn’t matter regardless to the script
yes, but why does the statement start with the opposite? Like it says opened is false but why does it then state if opened == true? How did it become true? Where does it call it to be true?
Again, it really doesn’t matter for this scenario in the order you place your if statements
cause your Opened
variable would check if it’s either true or false (Some UI’s by default are set to false, which would make sense)
The thing here is that this
local Opened = false
local Button = script.Parent
Button.MouseButton1Down:Connect(function()
if Opened == true then
Opened = false
--Tween your Button here when you want to close it
elseif Opened == false then
Opened = true
--Tween your Button here when you want to open it
end
end)
Is literally the same as this
local Opened = false
local Button = script.Parent
Button.MouseButton1Down:Connect(function()
if Opened == false then
Opened = true
--Tween your Button here when you want to open it
elseif Opened == true then
Opened = false
--Tween your Button here when you want to close it
end
end)
Both of these scripts will check if Opened
is equal to true or false, then set it to its opposite so that it can Tween the other way when your MouseButton1Down
event is fired again (Or when you click on the button), and it would set to its opposite yet again and vice versa
oh. That makes more sense. I thought that you were referring to the initial value.