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
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.
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)