My tweens only kinda work

I’m trying to tween the size of a GUI for a nice visual effect when opening a menu. The GUI is supposed to expand when opened, and shrink when closed. However, when I test my script, the GUI only tweens open. I’ve verified that both tweens work, but they don’t seem to want to work together. Below is my implementation:

local input = game:GetService("UserInputService")
local tween = game:GetService("TweenService")
--map is the GUI object to be tweened
local map = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Map

-- defining UI tweens
local open = {
	Size = UDim2.new(0, 386, 0, 572)
}
local close = {
	Size = UDim2.new(0, 1, 0, 1)
}

local tweenMap = TweenInfo.new(0.075, Enum.EasingStyle.Linear)
local tweenOpen = tween:Create(map, tweenMap, open)
local tweenClose = tween:Create(map, tweenMap, close)

local keybinds = {
	_101 = function()
		if map.Visible == false then
			map.Visible = not map.Visible
			tweenOpen:Play()
		else
			tweenClose:Play()
			map.Visible = not map.Visible
		end
	end,
}

input.InputBegan:Connect(function(InputObject)
	if InputObject.UserInputType == Enum.UserInputType.Keyboard then
		local val = InputObject.KeyCode.Value
		if val ~= 97 and val ~= 100 and val ~= 115 and val ~= 119 then --WASD
			if keybinds["_" .. tostring(InputObject.KeyCode.Value)] then
				keybinds["_" .. tostring(InputObject.KeyCode.Value)]() --I don't like lots of ifs
			end
		end
	end
end)
1 Like
			tweenClose:Play()
			map.Visible = not map.Visible

What you’re doing here is playing the tween and toggling visibility at the same time, meaning the tween is playing, the map just isn’t visible. Try using tweenClose.Completed:Connect() or :Wait()

1 Like

Thanks man! Thought it would wait on it’s own.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.