0% found this document useful (0 votes)
20 views

gui.lua

Uploaded by

khuonglamtan199
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

gui.lua

Uploaded by

khuonglamtan199
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

local ScreenGui = Instance.

new("ScreenGui")
local TextButton = Instance.new("TextButton")
local UICorner = Instance.new("UICorner")

ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
ScreenGui.Name = "ScreenGui"
ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling

TextButton.Name = "TextButton"
TextButton.Parent = ScreenGui
TextButton.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
TextButton.Position = UDim2.new(0.159199998, 0, 0.25920248, 0)
TextButton.Size = UDim2.new(0, 70, 0, 70)
TextButton.Font = Enum.Font.IndieFlower
TextButton.Text = "open"
TextButton.TextColor3 = Color3.fromRGB(255, 255, 255)
TextButton.TextSize = 41.000
TextButton.TextWrapped = true
TextButton.Visible = true

UICorner.Parent = TextButton

local toggleState = true

TextButton.MouseButton1Click:Connect(function()

toggleState = not toggleState -- Toggling the state


if toggleState then
TextButton.Text = "close"

game:GetService("VirtualInputManager"):SendKeyEvent(true,Enum.KeyCode.LeftControl,f
alse,game)
else
TextButton.Text = "open"

game:GetService("VirtualInputManager"):SendKeyEvent(true,Enum.KeyCode.LeftControl,f
alse,game)
end
end)

local function drag()


local script = Instance.new('LocalScript', TextButton)
local UIS = game:GetService('UserInputService')
local frame = script.Parent
local dragToggle = nil
local dragSpeed = 0.25
local dragStart = nil
local startPos = nil

local function updateInput(input)


local delta = input.Position - dragStart
local position = UDim2.new(startPos.X.Scale, startPos.X.Offset +
delta.X,
startPos.Y.Scale, startPos.Y.Offset + delta.Y)
game:GetService('TweenService'):Create(frame, TweenInfo.new(dragSpeed),
{Position = position}):Play()
end

frame.InputBegan:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.MouseButton1 or
input.UserInputType == Enum.UserInputType.Touch) then
dragToggle = true
dragStart = input.Position
startPos = frame.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
dragToggle = false
end
end)
end
end)

UIS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or
input.UserInputType == Enum.UserInputType.Touch then
if dragToggle then
updateInput(input)
end
end
end)

end
coroutine.wrap(drag)()

local function drag2()


local script = Instance.new('LocalScript', Frame)
local UIS = game:GetService('UserInputService')
local frame = script.Parent
local dragToggle = nil
local dragSpeed = 0.25
local dragStart = nil
local startPos = nil

local function updateInput(input)


local delta = input.Position - dragStart
local position = UDim2.new(startPos.X.Scale, startPos.X.Offset +
delta.X,
startPos.Y.Scale, startPos.Y.Offset + delta.Y)
game:GetService('TweenService'):Create(frame, TweenInfo.new(dragSpeed),
{Position = position}):Play()
end

frame.InputBegan:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.MouseButton1 or
input.UserInputType == Enum.UserInputType.Touch) then
dragToggle = true
dragStart = input.Position
startPos = frame.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
dragToggle = false
end
end)
end
end)

UIS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or
input.UserInputType == Enum.UserInputType.Touch then
if dragToggle then
updateInput(input)
end
end
end)

end
coroutine.wrap(drag2)()

You might also like