Reverse Variable Value

How would you reverse a variable value?

Currently im trying to create a function that can be called without inputting a value or boolean.

function GridUi:ToggleInventory()
	
	local StoredValue = false
	
	if StoredValue == true then
		GridPack.GuiElement.Visible = true
	elseif StoredValue == false then
		GridPack.GuiElement.Visible = false
	end
	
	
end

The reason im trying to do this is so I can have a toggle instead of hold with UIS

UserInputService.InputBegan:Connect(function(Input, IsTyping, GPE)
	
	if IsTyping == true or GPE == true then return end

	Maid:GiveTask(task.spawn(function()
		
		if Input.KeyCode == Enum.KeyCode.G then
			GridModule.ToggleInventory() -- Function just mentioned
		end
		
	end))
	
end)

DUDE HELP!

You can use not to reverse a variable boolean:

print(not true) = false
print(not false) = true

So, in your case it can be uhh this Instead I guess

function GridUi:ToggleInventory() --Every time it's called, it should toggle the visibility back and forth!!!!!!!!
	GridPack.GuiElement.Visible = not GridPack.GuiElement.Visible
end
1 Like