R

dragifyUi

public
rrixh Apr 06, 2024 Never 48
Clone
Lua dragifyUi_lulaslollipop.jpg 63 lines (51 loc) | 2.39 KB
1
-- This is a function that allows custom tweening and dragging of uis
2
-- A good config is Drag(UIObject, .25, "Circular", "Out") for background frames
3
4
local TweenService = game:GetService("TweenService")
5
local UserInputService = game:GetService("UserInputService")
6
local CoreGui = game:GetService("CoreGui")
7
8
local Tween = function(Object, Time, Style, Direction, Property)
9
return TweenService:Create(Object, TweenInfo.new(Time, Enum.EasingStyle[Style], Enum.EasingDirection[Direction]), Property)
10
end
11
12
local Drag = function(GuiObject, Time, Style, Direction)
13
task.spawn(function()
14
local StartPosition, Dragging, DragInput
15
local DragStart = Vector3.new()
16
17
local Update = function(Input)
18
local Delta = Input.Position - DragStart
19
local NewPosition = UDim2.new(StartPosition.X.Scale, StartPosition.X.Offset + Delta.X, StartPosition.Y.Scale, StartPosition.Y.Offset + Delta.Y)
20
21
Tween(GuiObject, Time, Style, Direction, {Position = NewPosition}):Play()
22
end
23
24
GuiObject.InputBegan:Connect(function(Input)
25
if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch then
26
Dragging = true
27
DragStart = Input.Position
28
StartPosition = GuiObject.Position
29
30
Input.Changed:Connect(function()
31
if Input.UserInputState == Enum.UserInputState.End then
32
Dragging = false
33
end
34
end)
35
end
36
end)
37
38
GuiObject.InputChanged:Connect(function(Input)
39
if Input.UserInputType == Enum.UserInputType.MouseMovement or Input.UserInputType == Enum.UserInputType.Touch then
40
DragInput = Input
41
end
42
end)
43
44
UserInputService.InputChanged:Connect(function(Input)
45
if Input == DragInput and Dragging then
46
Update(Input)
47
end
48
end)
49
end)
50
end
51
52
--3d illusion snake thing
53
for i = 1, 125 do
54
local GUI = Instance.new("ScreenGui", CoreGui)
55
local Frame = Instance.new("Frame",GUI)
56
Frame.BorderColor3 = Color3.fromRGB(255, 255, 255)
57
Frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
58
59
Frame.Position = UDim2.new(0, 0 + i / 100, 0, 0)
60
Frame.Size = UDim2.new(0, 50, 0, 50)
61
62
Drag(Frame, .1 + i / 100, "Sine", "Out")
63
end