A simple ah script wont work print at all?!?

ok I DONT KNOW WHAT BUT
THIS SIMPLE AH SCRIPT

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!
image
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!

1 Like

change close to cloose smth like that, do cloose = false

1 Like

another thing change cloose when tweening positions, your code is so wrong

1 Like

How is it wrong explain please.

1 Like

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)

1 Like

The only part that I think would error is that you have close as a variable so you could just change it to Closee

2 Likes

one thing @lV0rd and @weding3 it doesnt even print
image
this
image
-_-
so currently we have to figure out
WHY THE HELL IT WONT PRINT ANY THING!

1 Like

Maybe do a WaitForChild() because if it’s a local script then it will load almost instantly and you button may not have time to load

1 Like

I will rewrite this code.

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)
1 Like

You don’t need to make a close double o, even if it is a Roblox function already. From what I have learned from my Lua knowledge.

You could be right, though i’m not sure, i never let a variable name be a function.

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.

1 Like

You could test it right now. From my knowledge, any variable name you put on a script is always assigned to that script.

1 Like

Yes, just looked it up, and it does indeed work, thanks for this information :+1:

Here is the
Fixxed version :

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.

print is able to take infinite arguments…

1 Like

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.

1 Like

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)

1 Like

Print is a variadic function (receives a variable number of arguments).

local function VariadicFunction(...)
	warn(...)
end

VariadicFunction("Hello world!") --'Hello world!'.
VariadicFunction(1, 2, 3, 4, 5) --1 2 3 4 5
1 Like