If not value == 3 then/ if value ~= 3 then statement not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Make an interactive Gui

  2. What is the issue? If not value == 3 then/ if value ~= 3 then statements wont work

  3. What solutions have you tried so far? Tried putting the function inside the while loop but still the same

here is the entire local script for the GUI

local button = script.Parent
local orb = button.Orb
local top = button.Top
local bottom = button.Bottom
local glowfront = button.GlowFront
local glowback = button.GlowBack

local phase = 1

script.Parent.MouseEnter:Connect(function()
	phase = 3
end)

script.Parent.MouseLeave:Connect(function()
	phase = 1
end)

while script.Parent.Visible do
	wait()
	
	if phase == 3 then
		top:TweenPosition(
			UDim2.new(0, 0, 0, -5),
			"Out",
			"Quad",
			.7
		)

		bottom:TweenPosition(
			UDim2.new(0, 0, 0, 5),
			"Out",
			"Quad",
			.7
		)
	end
	
	if not phase == 3 then -- the problem starts here 
		print (phase.. "is not phase 3")
		if phase == 1 then

			top:TweenPosition(
				UDim2.new(0, 0, 0, -5),
				"Out",
				"Quad",
				.7
			)

			orb:TweenPosition(
				UDim2.new(0, 0, 0, -3),
				"Out",
				"Quad",
				.7
			)

			glowfront:TweenPosition(
				UDim2.new(0, 0, 0, -3),
				"Out",
				"Quad",
				.7
			)

			glowback:TweenPosition(
				UDim2.new(0, 0, 0, -3),
				"Out",
				"Quad",
				.7
			)

			bottom:TweenPosition(
				UDim2.new(0, 0, 0, -1),
				"Out",
				"Quad",
				.7
			)
			wait(.7)

			phase = 2

		elseif phase == 2 then

			top:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			orb:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			glowfront:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			glowback:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			bottom:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			wait(1)
			phase = 1
		end
	end
end

I don’t really know why this thing won’t work like what? if phase is not equals to 3 then print that but nothing happens

It’s because of the order of operations in Lua.
It is being read as (not phase) == 3
and not someNumber is false, so it boils down to if false == 3.
Just use
if phase ~= 3 then
or better yet, just use else. else is more efficient than doing another comparison.

3 Likes

Also from that snippet, you could make this a lot simpler to read and cut out the issue altogether by writing it as

if phase == 3 then
...
elseif phase == 2 then
...
elseif phase == 1 then
...
end
1 Like

I tried the codes and yeah it works fine, but… do tweens affect the latency of a local script?

cuz it’s still not working fine

here is a function that prints something when the mouse enters the button

script.Parent.MouseEnter:Connect(function()
	print("phase3")
	phase = 3
end)

and it’s outside the while loop… so yep it works fine as expected

but here is a similar code inside the while loop

(I already modified it cause I’m trying to fix the tween latency problem I’m thinking of)

if phase == 3 then
	print("phase3whileloop")
	tweenservice:Create(top, tweeninfo, {Position = UDim2.new(0, 0, 0, -5)}):Play()
	tweenservice:Create(bottom, tweeninfo, {Position = UDim2.new(0, 0, 0, 5)}):Play()
end

so it doesn’t work like the function outside the script, I meant is you need to enter and leave the button a couple of times before It prints

so I guess cancelling the tween when the phase changes will solve it, sadly there is no :Cancel on Gui:TweenPosition() so I’m going to use the tweenservice instead

From my understanding of tweens no, tweens should not yield/slow your script.

But if you are tweening on the server then you will notice lag. I would only recommend tweening on the client.

but how bout these lines of code tho

	if not phase == 3 then
		print (phase.. "is not phase 3")
		if phase == 1 then

			top:TweenPosition(
				UDim2.new(0, 0, 0, -5),
				"Out",
				"Quad",
				.7
			)

			orb:TweenPosition(
				UDim2.new(0, 0, 0, -3),
				"Out",
				"Quad",
				.7
			)

			glowfront:TweenPosition(
				UDim2.new(0, 0, 0, -3),
				"Out",
				"Quad",
				.7
			)

			glowback:TweenPosition(
				UDim2.new(0, 0, 0, -3),
				"Out",
				"Quad",
				.7
			)

			bottom:TweenPosition(
				UDim2.new(0, 0, 0, -1),
				"Out",
				"Quad",
				.7
			)
			wait(.7)

			phase = 2

		elseif phase == 2 then

			top:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			orb:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			glowfront:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			glowback:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			bottom:TweenPosition(
				UDim2.new(0, 0, 0, 0),
				"Out",
				"Quad",
				.7
			)

			wait(1)
			phase = 1
		end
	end

cuz while experimenting some things, I noticed that the codes outside of the while loop, works fine, while the codes inside the while loop doesn’t, and I think because of tween