Changing true to false

Ok, this is MIND BOGGLING! I am trying to set a very simple value to false and it won’t do it. This code is so easy and simple I don’t know what in the entire world I am doing wrong.

local TweenService = game:GetService("TweenService")
local Object = script.Parent

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut, 0, false, 0)

wait(1)
local canClick = true
local toggle = false
function onClick()
	if canClick == true then
		canClick = false
		local rot = Object.Rotation
		local Tween = TweenService:Create(Object, tweenInfo, {Rotation = rot == 360 and 0 or 360})
		if toggle == false then
			Tween:Play()
			wait(0.3)
			script.Parent.Parent.Frame:TweenSize(UDim2.new(0, 100, 0, 40), "Out", "Back", 1, false, nil)
			script.Parent.Parent.Frame.ImageButton.Position = UDim2.new(0.8, 0, 0.5, 0)
			Tween.Completed:Wait()
				toggle = true
			canClick = true
		else
			Tween:Play()
			wait(0.3)
			script.Parent.Parent.Frame:TweenSize(UDim2.new(0, 40, 0, 40), "In", "Back", 1, false, nil)
			wait(0.9)
			script.Parent.Parent.Frame.ImageButton.Position = UDim2.new(0.4, 0, 0.5, 0)
			Tween.Completed:Wait()
				toggle = false
			canClick = true
		end	
	end	
end
script.Parent.MouseButton1Click:Connect(onClick)

while true do
	wait(1)
	print(toggle)
end

When it is clicked the first time, it runs what is in the toggle == false, and then changes it to true, and but when it runs the else on the second click, it does not change it back to false.
robloxapp-20201231-1617057.wmv (442.9 KB)
I just don’t see it or get it. My guess is that I am missing something so obvious I will laugh at myself when it is figured out.

Also, how do I post clips on the forum that appear as just clickable videos, because every time I try to upload something it comes up as something that needs to be downloaded, as you can see above.

2 Likes

It is very, very strange, and it makes 0 sense… MIND BOGGLING…

I basically remade the code, eliminating everything that was unrelated to actually changing the bool value and it works fine. Is the code not performing what you expect, or is your loop just not printing the value accurately? I also assigned it to a keyboard press for ease of use for me, but it’s the same basic concept. I think something deeper is wrong if it isn’t working.

local toggle = false
local canClick = true

function onClick()
	if canClick then
		canClick = false
		if toggle == false then
			print(toggle)
			toggle = true
			canClick = true
		else
			print(toggle)
			toggle = false
			canClick = true
		end
	end
end

uis.InputBegan:Connect(function(input, gameprocessed) 
	if input.UserInputType == Enum.UserInputType.Keyboard then 
		local keyPressed = input.keyCode
		if keyPressed == Enum.KeyCode.Q then
			onClick()
		end
	end
end)
1 Like

It wasn’t printing right(as in it was printing true when it was obviously supposed to be false) AND it wouldn’t do what I wanted it to.

I think the printing issue is related to it being in a timed loop. Just print it where I did and it will print the exact value when and where you need it printed. Maybe in the else statement, right after you change toggle back to false, put a print(toggle) there and make sure it is actually turning false. If not, maybe something is happening when you wait for that tween to complete?

Ok, I took away the tween.completed:wait() and I guess that was what was causing the problem

1 Like