Tween Gui | How To Do It?

Hello! So I am not very good with TweenService yet, but I need a script which when a part is clicked using a ClickDetector, it will tween a Gui up from the bottom of the screen to the middle! Here’s all the data: The script will be inside the part, which has a ClickDetector already named ClickDetector. The ScreenGui is located in StarterGui, and is called OrderingSystem. Inside the ScreenGui is a Frame named Frame. Thanks for the help in advance! :grinning:

Using the documentation from TweenPosition() we can move any UI instance.
TweenPosition takes many arguments so I’ll comment each one:

local Frame = script.Parent.Frame

Frame:TweenPosition( --Run function
	UDim2.new(0.5, 0, 0.5, 0), --Final position of tween
	Enum.EasingDirection.Out, --Alternatively you can just provide the string "Out"
	Enum.EasingStyle.Quad, --Easing style / "Quad"
	0.1, --Time taken to finish tween
	false, --OPTIONAL (DEFAULT IS FALSE) If another tween can overwrite it
	callback(), --OPTIONAL (DEFAULT IS NIL / NONE) calls a function when tween finishes
)

You may want to look into AnchorPoint as well as it will help with positioning UI instances correctly and help with your tweening.

1 Like

Put this inside the ClickDetector:

script.Parent.MouseClick:Connect(function(player)
	local PlayerGui = player:WaitForChild("PlayerGui")
	local GUI = PlayerGui:WaitForChild("OrderingSystem")
	local Frame = GUI:WaitForChild("Frame")
	local TweenTime = 0.4
	local Position = UDim2.new(0.5, 0,0.5, 0) -- You can adjust if needed
    Frame.AnchorPoint = Vector2.new(0.5,0.5)
	Frame:TweenPosition(Position,Enum.EasingDirection.Out,Enum.EasingStyle.Sine,TweenTime)
end)

You do not need to use TweenService for this, you can use the TweenPosition function which is automatically assigned to Frames. TweenService is mainly used for tweening other properties.

Note: Sometimes this script will not work, due to exploiters changing the position of their frame, so you can use RemoteEvents to get to the client if needed.

RemoteEvent method

Create RemoteEvent called “TweenOpen” in ReplicatedStorage.

ServerScript inside ClickDetector:

local Event = game.ReplicatedStorage:WaitForChild("TweenOpen")

script.Parent.MouseClick:Connect(function(player)
	Event:FireClient(player)
end)

LocalScript in StarterGui:

local Event = game.ReplicatedStorage:WaitForChild("TweenOpen")

local function PropertyExists(obj, prop)
	return ({pcall(function()if(typeof(obj[prop])=="Instance")then error()end end)})[1]
end

function SetSize(v,params)
	if params == "Scale" then
		if PropertyExists(v, "Size") then
			local Viewport_Size

			if PropertyExists(v.Parent, "AbsoluteSize") then
				Viewport_Size = v.Parent.AbsoluteSize
			elseif v:FindFirstAncestorWhichIsA("GuiObject") and PropertyExists(v:FindFirstAncestorWhichIsA("GuiObject"), "AbsoluteSize") then
				Viewport_Size = v:FindFirstAncestorWhichIsA("GuiObject").AbsoluteSize
			else
				Viewport_Size = workspace.CurrentCamera.ViewportSize
			end

			local LB_Size = v.AbsoluteSize
			v.Size = UDim2.new(LB_Size.X/Viewport_Size.X,0,LB_Size.Y/Viewport_Size.Y, 0)
		end
	elseif params == "Offset" then	
		if PropertyExists(v, "Size")then
			local LB_Size = v.AbsoluteSize
			v.Size = UDim2.new(0, LB_Size.X, 0, LB_Size.Y)
		end
	end
end

local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local GUI = PlayerGui:WaitForChild("OrderingSystem")
local Frame = GUI:WaitForChild("Frame")
SetSize(Frame,"Scale")
Frame.AnchorPoint = Vector2.new(0,0)

Event.OnClientEvent:Connect(function()
	local TweenTime = 0.4
	local Position = UDim2.new(0.434, 0,0.4, 0) -- You can adjust if needed
	Frame:TweenPosition(Position,Enum.EasingDirection.Out,Enum.EasingStyle.Sine,TweenTime)
end)
1 Like

Okay! I will test this right now!

Thank you for clearing that up for me! (:

local Position = UDim2.new(0.434, 0,0.4, 0)

This line here is a bad way to position UI, assuming that you haven’t implemented AnchorPoint this position may only be the middle of your own device and not others. An example I made can be seen here:

Always make sure your UI works on all devices.

Update: Sorry I haven’t gotten back to you. I used the remote event one, adding onto the script just creating a Blur when the event is fired, however, the GUI doesn’t show up.