Tween Not working

Tring to make it so once the button is pressed it will tween.
I’ve had another scripter try and help me w/ it but w/ no luck

local imagebtn = script.Parent
local frame = script.Parent.Parent.Frame
local on = false

local function onActivated()
	if on == false then
		print("one")
		frame.Visible = true
		on = true
		print("one_and_a_half")
		frame:TweenPosition(UDim2.new(0.08 , 0.326)) -- Put the position to tween to. 
	elseif on == true then
		print("two")
		frame.Visible = false
		on = false
		print("two_and_a_half")
		frame:TweenPosition(UDim2.new(-1 , 0.326)) -- Put the position to tween back to
	end
end
print("almost_done")
imagebtn.Activated:Connect(onActivated)
print("actually_done")

for some reason it skips
print(two) and print(two_and_a_half)

Okay, you should swap this part around

replace it with this

if on then
		print("two")
		frame.Visible = false
		on = false
		print("two_and_a_half")
		frame:TweenPosition(UDim2.new(-1 , 0.326)) -- Put the position to tween back to
	else
		print("one")
		frame.Visible = true
		on = true
		print("one_and_a_half")
		frame:TweenPosition(UDim2.new(0.08 , 0.326)) -- Put the position to tween to. 
	end

Not sure if it will fix it, but I know it’s a better way to code it.

Youre missing almost every parameter of the tween, you didn’t define the easing style, easing direction, duration, etc.

@ImTheBuildGuy , I don’t think this will work. I might be wrong, but here’s why:

Here they are checking if the value is false, this would evaluate to true, but then it’s being set to true.

Here they are checking if the value is true, then setting it false. If you used an else statement, you’re essentially saying if something isn’t “x”, do this. Since the condition is whether ‘on’ is equal to true, the else statement would only be true if ‘on’ is false. I don’t believe else statements account for what happens to the condition being checked as it changes. The value is being changed, therefore you would need to use 2 if statements.

Basically:

local BoolValue = false

if BoolValue then -- If something is true then
    print('true') 
end

if BoolValue == false then
	BoolValue = true
	print('true') 
else -- Wouldn't evaluate to true because the condition is whether it's false
	BoolValue = false
	print('false')
end

if BoolValue == false then 
    BoolValue = true
    print('false') -- prints
elseif BoolValue == true then -- doesn't evaluate 
    print('true')
end

In Op’s case, they are using the 3rd example above. It wouldn’t evaluate to true because the value is false, even though it has been set to true. You could something like:

local imagebtn = script.Parent
local frame = script.Parent.Parent.Frame
on = false

local function onActivated()
	if on == false then
		print("one")
		frame.Visible = true
		on = true
		print("one_and_a_half")
		frame:TweenPosition(UDim2.new(0.685, 0, 0.098, 0)) -- Put the position to tween to. 
	if on == true then
		print("two")
		frame.Visible = true
		on = false
		print("two_and_a_half")
		frame:TweenPosition(UDim2.new(0.049, 0, 0.526, 0)) -- Put the position to tween back to
		end
	end
end
imagebtn.Activated:Connect(onActivated)

if on then will check if its true, you don’t need the == true, it does nothing ;-;

1 Like

Ik, I just used it because ‘on’ was initially false.

The else checks if it’s false, I don’t get your point.

Your else statement doesn’t account for the Value changing within the condition. Only one half of your code would evaluate as true, which is not what OP wants to achieve.

1 Like

my brain is melting so ok i guess

1 Like