I Have a Problem Tweening my Gui on the Y-Axis!

As the Title Suggests I have a Problem with Tweeting my Gui on the Y-axis

Here is a video of the Problem

And the Code

function TweenGuiX(WhatTotween)
	if WhatTotween.Visible == false then
		-- Tweens it so it will show up
		-- Calculates the new position
		local newX = (WhatTotween.AbsolutePosition.X - WhatTotween.AbsoluteSize.X) / VeiwPortSize.X
		local newY = WhatTotween.Position.Y

		local newPosition = UDim2.new(newX, 0, newY, 0)
		WhatTotween.Visible = true
		WhatTotween:TweenPosition(newPosition,Enum.EasingDirection.In,Enum.EasingStyle.Linear,.2,false)
	else
		-- tweens it so it wont show
		local newX = (WhatTotween.AbsolutePosition.X + WhatTotween.AbsoluteSize.X) / VeiwPortSize.X
		local newY = WhatTotween.Position.Y

		local newPosition = UDim2.new(newX, 0, newY, 0)
		local Hide = function ()
			WhatTotween.Visible = false 
		end
		WhatTotween:TweenPosition(newPosition,Enum.EasingDirection.In,Enum.EasingStyle.Linear,.2,false,Hide)
	end
end
function TweenGuiY(WhatTotween)
	local Position = WhatTotween.Position
	if WhatTotween.Visible == false then
		-- Tweens it so it will show up
		-- Calculates the new position
		local newX = Position.X
		local newY = (WhatTotween.AbsolutePosition.Y + WhatTotween.AbsoluteSize.Y) / VeiwPortSize.Y
		print(newY)
		local newPosition = UDim2.new(newX, 0, newY, 0)
		
		WhatTotween.Visible = true
		
		WhatTotween:TweenPosition(newPosition,Enum.EasingDirection.In,Enum.EasingStyle.Linear,.2,false)
	else
		-- tweens it so it wont show
		local newX = Position.X
		local newY = (WhatTotween.AbsolutePosition.Y - WhatTotween.AbsoluteSize.Y) / VeiwPortSize.Y
		print(newY)
		local newPosition = UDim2.new(newX, 0, newY, 0)
		
		local Hide = function ()
			WhatTotween.Visible = false 
		end
		WhatTotween:TweenPosition(newPosition,Enum.EasingDirection.In,Enum.EasingStyle.Linear,.2,false,Hide)
	end
end
UI.BackPackButton.MouseButton1Up:Connect(function()
	TweenGuiX(Inventory)
	TweenGuiY(Crafting)
end)
UIS.InputBegan:Connect(function(Input,gameProcessed)
	if Input.KeyCode == Enum.KeyCode.C then
		TweenGuiX(Inventory)
		TweenGuiY(Crafting)
	end
end)

also, where the Gui is supposed to go on the Y-axis
image

Pls help :pray: :pray: :pray:

3 Likes

TweenPosition

bool

Deprecated

This function is deprecated in favor of using TweenService, which allows for better customization using an object-oriented and event-based approach.

  • The easingDirection, easingStyle, and time parameters are handled by a TweenInfo

  • The override parameter is no longer relevant; tweens always override previous tweens on the same property.

  • The callback parameter is better suited by the Tween.Completed event. The Enum.PlaybackState enum passed by that event provides a more detailed description of the tween’s completion state.

1 Like

Thank You I will Try That in my Code

1 Like

New Code with the TweenService

local Player = game.Players.LocalPlayer
local Inventory = Player.PlayerGui:WaitForChild("Inventory").InventoryFrame
local Crafting = Player.PlayerGui:WaitForChild("Crafting").Crafting
local UI = Player.PlayerGui:WaitForChild("UI")
local UIS = game:GetService("UserInputService")
local VeiwPortSize = game.Workspace.CurrentCamera.ViewportSize
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.2,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
-- Requirers the ModuleScripts
local InventoryItems = require(Player.PlayerScripts:WaitForChild("ItemsInInventory"))

local InventoryEvent = game.ReplicatedStorage.RemoteEvents.InventoryEvent

InventoryEvent.OnClientEvent:Connect(function(Item,player)
	InventoryItems.AddSlot(player,Item)
end)
function TweenGuiX(WhatTotween)
	if WhatTotween.Visible == false then
		-- Tweens it so it will show up
		-- Calculates the new position
		local newX = (WhatTotween.AbsolutePosition.X - WhatTotween.AbsoluteSize.X) / VeiwPortSize.X
		local newY = WhatTotween.Position.Y

		local newPosition = UDim2.new(newX, 0, newY, 0)
		WhatTotween.Visible = true
		local tween = TS:Create(WhatTotween,TI,{Position = newPosition})
		tween:Play()
	else
		-- tweens it so it wont show
		local newX = (WhatTotween.AbsolutePosition.X + WhatTotween.AbsoluteSize.X) / VeiwPortSize.X
		local newY = WhatTotween.Position.Y

		local newPosition = UDim2.new(newX, 0, newY, 0)
		local tween = TS:Create(WhatTotween,TI,{Position = newPosition})
		tween:Play()
		
		tween.Completed:Connect(function()
			WhatTotween.Visible = false
		end)
	end
end
function TweenGuiY(WhatTotween)
	local Position = WhatTotween.Position
	if WhatTotween.Visible == false then
		-- Tweens it so it will show up
		-- Calculates the new position
		local newX = Position.X
		local newY = (WhatTotween.AbsolutePosition.Y + WhatTotween.AbsoluteSize.Y) / VeiwPortSize.Y
		print(newY)
		local newPosition = UDim2.new(newX, 0, newY, 0)
		
		WhatTotween.Visible = true
		
		local tween = TS:Create(WhatTotween,TI,{Position = newPosition})
		tween:Play()
	else
		-- tweens it so it wont show
		local newX = Position.X
		local newY = (WhatTotween.AbsolutePosition.Y - WhatTotween.AbsoluteSize.Y) / VeiwPortSize.Y
		print(newY)
		local newPosition = UDim2.new(newX, 0, newY, 0)
		
		local tween = TS:Create(WhatTotween,TI,{Position = newPosition})
		tween:Play()

		tween.Completed:Connect(function()
			WhatTotween.Visible = false
		end)
	end
end
UI.BackPackButton.MouseButton1Up:Connect(function()
	TweenGuiX(Inventory)
	TweenGuiY(Crafting)
end)
UIS.InputBegan:Connect(function(Input,gameProcessed)
	if Input.KeyCode == Enum.KeyCode.C then
		TweenGuiX(Inventory)
		TweenGuiY(Crafting)
	end
end)

It sadly still doesn’t work :sob: :sob: :sob:

1 Like

And why do you tween an object to its position at the time?

In that Piece of Code I Didn’t Want the Y Coordinate to Change Because I only Wanted the X to Change and to Make it Look Better

newX should give you 2 numbers -
image
so you can try doing like this - local newPosition = UDim2.new(newX, newY, 0)
or UDim2.new(newX.Scale, newX.Offset, newY, 0)

The First Number on the X is the Scale, and the Other is Offset

I Want to Use Scale

You Only use One of the Values

But newX gives you scale and offset so you put five numbers there instead of 4 , just remove 0 after newX

image
This is What the newY Gives
One Number