local Base = script.Parent
local Button = Base.OpenClose
local close = true
Button.MouseButton1Click:Connect(function()
print("Clicked",tostring(close))
close = not close
if close then
Base:TweenPosition(UDim2.new(-0.165,0,0.5,0),"Out","Sine",0.5)
else
Base:TweenPosition(UDim2.new(0,0,0.5,0),"Out","Sine",0.5)
end
end)
WONT WORK!
as you can see my button is a button. The closer is this script. Holder is nothing. Base yknow. Menu screen UI. NOW WHY THE HELL WONT THAT WORK? I AM GOING INSANE!
Ok so, when you tween position, you check if close is true, when before that if statement close is not.
And, when you tween the position you dont change close. Which doesnât make sense if youâd add else statement. Print isnât good. Just do print("Clicked")
ONE OTHER THINg, IN THE IF STATEMENT YOU DID THE POSITION WRONG. ITS SUPPOSED TO BE UDim2.new(-1.165,0,0.5,0)
local Base = script.Parent
local Button = Base.OpenClose
local cloose = true
Button.MouseButton1Click:Connect(function()
print("Clicked")
cloose = false
if cloose then
Base:TweenPosition(UDim2.new(-1.165,0,0.5,0),"Out","Sine",0.5, true)
cloose = false
else
cloose = true
Base:TweenPosition(UDim2.new(0.165,0,0.5,0),"Out","Sine",0.5, true)--Changes
end
end)
Why did you use tostring(close)?!?! It is not necessary, since youâre not using a textbox to find the local playerâs input. You couldâve just written in the variableâs name.
local Base = script.Parent
local Button = Base.OpenClose
local Close = true
Button.MouseButton1Click:Connect(function()
print("Clicked" .. tostring(Close))
Close = not Close
if Close then
Base:TweenPosition(UDim2.new(-0.165,0,0.5,0),"Out","Sine",0.5)
else
Base:TweenPosition(UDim2.new(0,0,0.5,0),"Out","Sine",0.5)
end
end)
notify me if any error pops up.
Reasons is you used a , in a print and not .. for a string
and Possibly could had a failed variable (but i dont think thats why it broke but i changed it either way)
Try Button.Activated:Connect make sure your OpenClose button is set to Active. If you have any errors in the output please show them, but I assume âwont print at allâ means no errors.
Yeah no. His way of operating the close variable is completely fine, and the code you âfixedâ will not work properly. You set the variable to false on every click, which not only removes the point of it being a global variable but will not toggle it true/false.
And, you do not need to name your variables differently in case of a naming conflict with pre-made globals.
Make sure the script is a local script, and make sure that itâs a child of âBaseâ
Also I made an edit to where the button is not inside of the Base, since that would make it unopenable if it goes off screen
local Base = script.Parent
local Button = Base.Parent.OpenClose
local close = true
Button.MouseButton1Click:Connect(function()
print("Clicked", close)
if close == true then
Base:TweenPosition(UDim2.new(0.5, -800, 0.5, 0),"Out","Sine",0.5)
-- The reason it's 0.5 -800 is so it goes offscreen, so it stays on the same scale, but the X Offset is the Base.Size.X.Offset * 2
else
Base:TweenPosition(UDim2.new(0.5, 0, 0.5, 0),"Out","Sine",0.5)
-- This just recenters it if it is offscreen.
end
-- The reason this is called after the rest of the script is so it doesn't be true when it should be false, and vice versa
close = not close
end)
Video example of the script:
(Sorry for the lag, it was the video, not the script btw)