Ghi chú phát hành
Học
Lớp công cụ
GuiObject
Không Thể Tạo
Không Thể Duyệt

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm Tắt
Phương Pháp
TweenPosition(endPosition: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean
Đã Lỗi Thời
TweenSize(endSize: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean
Đã Lỗi Thời
TweenSizeAndPosition(endSize: UDim2,endPosition: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean
Đã Lỗi Thời
Thành viên kế thừa
Được kế thừa bởi

Tài Liệu Tham Khảo API
Thuộc Tính
Active
Đọc Song Song
Các khả năng: UI
GuiObject.Active:boolean
Mẫu mã
Nút Văn Bản Hoạt Động Lùi
-- Đặt LocalScript này bên trong một TextButton (hoặc ImageButton)
local textButton = script.Parent
textButton.Text = "Nhấn vào tôi"
textButton.Active = true
local function onActivated()
-- Điều này hoạt động như một bộ lùi
textButton.Active = false
-- Đếm ngược từ 5
for i = 5, 1, -1 do
textButton.Text = "Thời gian: " .. i
task.wait(1)
end
textButton.Text = "Nhấn vào tôi"
textButton.Active = true
end
textButton.Activated:Connect(onActivated)

AnchorPoint
Đọc Song Song
Các khả năng: UI
GuiObject.AnchorPoint:Vector2
Mẫu mã
Ví dụ về AnchorPoint
local guiObject = script.Parent
while true do
-- Góc trên bên trái
guiObject.AnchorPoint = Vector2.new(0, 0)
guiObject.Position = UDim2.new(0, 0, 0, 0)
task.wait(1)
-- Trên
guiObject.AnchorPoint = Vector2.new(0.5, 0)
guiObject.Position = UDim2.new(0.5, 0, 0, 0)
task.wait(1)
-- Góc trên bên phải
guiObject.AnchorPoint = Vector2.new(1, 0)
guiObject.Position = UDim2.new(1, 0, 0, 0)
task.wait(1)
-- Bên trái
guiObject.AnchorPoint = Vector2.new(0, 0.5)
guiObject.Position = UDim2.new(0, 0, 0.5, 0)
task.wait(1)
-- Trung tâm
guiObject.AnchorPoint = Vector2.new(0.5, 0.5)
guiObject.Position = UDim2.new(0.5, 0, 0.5, 0)
task.wait(1)
-- Bên phải
guiObject.AnchorPoint = Vector2.new(1, 0.5)
guiObject.Position = UDim2.new(1, 0, 0.5, 0)
task.wait(1)
-- Góc dưới bên trái
guiObject.AnchorPoint = Vector2.new(0, 1)
guiObject.Position = UDim2.new(0, 0, 1, 0)
task.wait(1)
-- Dưới
guiObject.AnchorPoint = Vector2.new(0.5, 1)
guiObject.Position = UDim2.new(0.5, 0, 1, 0)
task.wait(1)
-- Góc dưới bên phải
guiObject.AnchorPoint = Vector2.new(1, 1)
guiObject.Position = UDim2.new(1, 0, 1, 0)
task.wait(1)
end

AutomaticSize
Đọc Song Song
Các khả năng: UI
GuiObject.AutomaticSize:Enum.AutomaticSize
Mẫu mã
LocalScript trong một ScreenGui
-- Mảng các nhãn/văn bản/phông chữ/kích thước để xuất
local labelArray = {
{ text = "Lorem", font = Enum.Font.Creepster, size = 50 },
{ text = "ipsum", font = Enum.Font.IndieFlower, size = 35 },
{ text = "dolor", font = Enum.Font.Antique, size = 55 },
{ text = "sit", font = Enum.Font.SpecialElite, size = 65 },
{ text = "amet", font = Enum.Font.FredokaOne, size = 40 },
}
-- Tạo một khung cha có kích thước tự động
local parentFrame = Instance.new("Frame")
parentFrame.AutomaticSize = Enum.AutomaticSize.XY
parentFrame.BackgroundColor3 = Color3.fromRGB(90, 90, 90)
parentFrame.Size = UDim2.fromOffset(25, 100)
parentFrame.Position = UDim2.fromScale(0.1, 0.1)
parentFrame.Parent = script.Parent
-- Thêm một bố cục danh sách
local listLayout = Instance.new("UIListLayout")
listLayout.Padding = UDim.new(0, 5)
listLayout.Parent = parentFrame
-- Đặt các góc tròn và lề cho yếu tố thẩm mỹ
local roundedCornerParent = Instance.new("UICorner")
roundedCornerParent.Parent = parentFrame
local uiPaddingParent = Instance.new("UIPadding")
uiPaddingParent.PaddingTop = UDim.new(0, 5)
uiPaddingParent.PaddingLeft = UDim.new(0, 5)
uiPaddingParent.PaddingRight = UDim.new(0, 5)
uiPaddingParent.PaddingBottom = UDim.new(0, 5)
uiPaddingParent.Parent = parentFrame
for i = 1, #labelArray do
-- Tạo một nhãn văn bản có kích thước tự động từ mảng
local childLabel = Instance.new("TextLabel")
childLabel.AutomaticSize = Enum.AutomaticSize.XY
childLabel.Size = UDim2.fromOffset(75, 15)
childLabel.Text = labelArray[i]["text"]
childLabel.Font = labelArray[i]["font"]
childLabel.TextSize = labelArray[i]["size"]
childLabel.TextColor3 = Color3.new(1, 1, 1)
childLabel.Parent = parentFrame
-- Thẩm mỹ
local roundedCorner = Instance.new("UICorner")
roundedCorner.Parent = childLabel
local uiPadding = Instance.new("UIPadding")
uiPadding.PaddingTop = UDim.new(0, 5)
uiPadding.PaddingLeft = UDim.new(0, 5)
uiPadding.PaddingRight = UDim.new(0, 5)
uiPadding.PaddingBottom = UDim.new(0, 5)
uiPadding.Parent = childLabel
task.wait(2)
end

BackgroundColor
Đã Lỗi Thời

BackgroundColor3
Đọc Song Song
Các khả năng: UI
GuiObject.BackgroundColor3:Color3
Mẫu mã
Khung Cầu Vồng
-- Đặt mã này trong một LocalScript trong một Frame
local frame = script.Parent
while true do
for hue = 0, 255, 4 do
-- HSV = sắc độ, độ bão hòa, giá trị
-- Nếu chúng ta lặp lại từ 0 đến 1 nhiều lần, chúng ta sẽ có một cầu vồng!
frame.BorderColor3 = Color3.fromHSV(hue / 256, 1, 1)
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, 0.5, 0.8)
task.wait()
end
end

BackgroundTransparency
Đọc Song Song
Các khả năng: UI
GuiObject.BackgroundTransparency:number

BorderColor
Đã Lỗi Thời

BorderColor3
Đọc Song Song
Các khả năng: UI
GuiObject.BorderColor3:Color3
Mẫu mã
Nút Đánh Dấu
-- Đặt tôi bên trong một GuiObject, tốt nhất là một ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Vàng
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Đen
end
-- Kết nối sự kiện
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Trạng thái mặc định của chúng tôi là "không được đánh dấu"
onLeave()

BorderMode
Đọc Song Song
Các khả năng: UI
GuiObject.BorderMode:Enum.BorderMode

BorderSizePixel
Đọc Song Song
Các khả năng: UI
GuiObject.BorderSizePixel:number
Mẫu mã
Nút Đánh Dấu
-- Đặt tôi bên trong một GuiObject, tốt nhất là một ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Vàng
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Đen
end
-- Kết nối sự kiện
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Trạng thái mặc định của chúng tôi là "không được đánh dấu"
onLeave()

ClipsDescendants
Đọc Song Song
Các khả năng: UI
GuiObject.ClipsDescendants:boolean

Draggable
Đã Lỗi Thời

GuiState
Chỉ Đọc
Không Sao Chép
Đọc Song Song
Các khả năng: UI
GuiObject.GuiState:Enum.GuiState

InputSink
Đọc Song Song
Các khả năng: UI
GuiObject.InputSink:Enum.InputSink

Interactable
Đọc Song Song
Các khả năng: UI
GuiObject.Interactable:boolean

LayoutOrder
Đọc Song Song
Các khả năng: UI
GuiObject.LayoutOrder:number

NextSelectionDown
Đọc Song Song
Các khả năng: UI
GuiObject.NextSelectionDown:GuiObject
Mẫu mã
Tạo một Lưới Lựa chọn Gamepad
-- Thiết lập lưới lựa chọn Gamepad bằng mã dưới đây
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Cạnh trái
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Cạnh phải
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Trên
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Dưới
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Kiểm tra lưới lựa chọn Gamepad bằng mã dưới đây
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)

NextSelectionLeft
Đọc Song Song
Các khả năng: UI
GuiObject.NextSelectionLeft:GuiObject
Mẫu mã
Tạo một Lưới Lựa chọn Gamepad
-- Thiết lập lưới lựa chọn Gamepad bằng mã dưới đây
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Cạnh trái
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Cạnh phải
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Trên
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Dưới
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Kiểm tra lưới lựa chọn Gamepad bằng mã dưới đây
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)

NextSelectionRight
Đọc Song Song
Các khả năng: UI
GuiObject.NextSelectionRight:GuiObject
Mẫu mã
Tạo một Lưới Lựa chọn Gamepad
-- Thiết lập lưới lựa chọn Gamepad bằng mã dưới đây
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Cạnh trái
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Cạnh phải
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Trên
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Dưới
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Kiểm tra lưới lựa chọn Gamepad bằng mã dưới đây
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)

NextSelectionUp
Đọc Song Song
Các khả năng: UI
GuiObject.NextSelectionUp:GuiObject
Mẫu mã
Tạo một Lưới Lựa chọn Gamepad
-- Thiết lập lưới lựa chọn Gamepad bằng mã dưới đây
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Cạnh trái
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Cạnh phải
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Trên
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Dưới
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Kiểm tra lưới lựa chọn Gamepad bằng mã dưới đây
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)

Position
Đọc Song Song
Các khả năng: UI
GuiObject.Position:UDim2

Rotation
Đọc Song Song
Các khả năng: UI
GuiObject.Rotation:number

Selectable
Đọc Song Song
Các khả năng: UI
GuiObject.Selectable:boolean
Mẫu mã
Giới Hạn Lựa Chọn TextBox
local GuiService = game:GetService("GuiService")
local textBox = script.Parent
local function gainFocus()
textBox.Selectable = true
GuiService.SelectedObject = textBox
end
local function loseFocus(_enterPressed, _inputObject)
GuiService.SelectedObject = nil
textBox.Selectable = false
end
-- Sự kiện FocusLost và FocusGained sẽ được kích hoạt vì textBox
-- thuộc loại TextBox
textBox.Focused:Connect(gainFocus)
textBox.FocusLost:Connect(loseFocus)

SelectionImageObject
Đọc Song Song
Các khả năng: UI
GuiObject.SelectionImageObject:GuiObject

SelectionOrder
Đọc Song Song
Các khả năng: UI
GuiObject.SelectionOrder:number

Size
Đọc Song Song
Các khả năng: UI
GuiObject.Size:UDim2
Mẫu mã
Thẻ Sức Khỏe
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Dán mã vào một LocalScript được
-- gán làm cha cho một khung bên trong khung
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- đen
-- Hàm này được gọi khi sức khỏe của humanoid thay đổi
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Thay đổi kích thước của thanh bên trong
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Thay đổi màu sắc của thẻ sức khỏe
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- đỏ
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- vàng
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- xanh
end
end
-- Hàm này được gọi khi người chơi xuất hiện
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Cách thức: cập nhật một lần bây giờ, sau đó bất kỳ lúc nào sức khỏe thay đổi
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Kết nối trình nghe cho lần xuất hiện; gọi nó nếu đã xuất hiện
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end

SizeConstraint
Đọc Song Song
Các khả năng: UI
GuiObject.SizeConstraint:Enum.SizeConstraint

Transparency
Đã Lỗi Thời

Visible
Đọc Song Song
Các khả năng: UI
GuiObject.Visible:boolean
Mẫu mã
Cửa sổ UI
local gui = script.Parent
local window = gui:WaitForChild("Window")
local toggleButton = gui:WaitForChild("ToggleWindow")
local closeButton = window:WaitForChild("Close")
local function toggleWindowVisbility()
-- Đảo ngược một boolean bằng cách sử dụng từ khóa `not`
window.Visible = not window.Visible
end
toggleButton.Activated:Connect(toggleWindowVisbility)
closeButton.Activated:Connect(toggleWindowVisbility)

ZIndex
Đọc Song Song
Các khả năng: UI
GuiObject.ZIndex:number

Phương Pháp
TweenPosition
Đã Lỗi Thời

TweenSize
Đã Lỗi Thời

TweenSizeAndPosition
Đã Lỗi Thời

Sự Kiện
DragBegin
Đã Lỗi Thời

DragStopped
Đã Lỗi Thời

InputBegan
Các khả năng: UI
GuiObject.InputBegan(input:InputObject):RBXScriptSignal
Tham Số
Mẫu mã
Theo dõi sự bắt đầu của đầu vào trên GuiObject
-- Để sử dụng sự kiện InputBegan, bạn phải chỉ định GuiObject
local gui = script.Parent
-- Một hàm mẫu cung cấp nhiều trường hợp sử dụng cho các loại đầu vào của người dùng khác nhau
local function inputBegan(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("Một phím đang được nhấn xuống! Phím:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Nút chuột trái đã được nhấn xuống tại", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Nút chuột phải đã được nhấn xuống tại", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("Một đầu vào cảm ứng đã bắt đầu tại", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("Một nút đang được nhấn trên một tay cầm trò chơi! Nút:", input.KeyCode)
end
end
gui.InputBegan:Connect(inputBegan)

InputChanged
Các khả năng: UI
GuiObject.InputChanged(input:InputObject):RBXScriptSignal
Tham Số
Mẫu mã
Ví dụ về InputChanged của GuiObject
local UserInputService = game:GetService("UserInputService")
local gui = script.Parent
local function printMovement(input)
print("Vị trí:", input.Position)
print("Delta chuyển động:", input.Delta)
end
local function inputChanged(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
print("Chuột đã được di chuyển!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
print("Bánh xe chuột đã được cuộn!")
print("Chuyển động bánh xe:", input.Position.Z)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.Thumbstick1 then
print("Cần điều khiển bên trái đã được di chuyển!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
print("Cần điều khiển bên phải đã được di chuyển!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
print("Áp lực đang được tác động lên cò trái đã thay đổi!")
print("Áp lực:", input.Position.Z)
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
print("Áp lực đang được tác động lên cò phải đã thay đổi!")
print("Áp lực:", input.Position.Z)
end
elseif input.UserInputType == Enum.UserInputType.Touch then
print("Ngón tay của người dùng đang di chuyển trên màn hình!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.Gyro then
local _rotInput, rotCFrame = UserInputService:GetDeviceRotation()
local rotX, rotY, rotZ = rotCFrame:toEulerAnglesXYZ()
local rot = Vector3.new(math.deg(rotX), math.deg(rotY), math.deg(rotZ))
print("Góc xoay của thiết bị di động của người dùng đã được thay đổi!")
print("Vị trí", rotCFrame.p)
print("Góc xoay:", rot)
elseif input.UserInputType == Enum.UserInputType.Accelerometer then
print("Gia tốc của thiết bị di động của người dùng đã được thay đổi!")
printMovement(input)
end
end
gui.InputChanged:Connect(inputChanged)

InputEnded
Các khả năng: UI
GuiObject.InputEnded(input:InputObject):RBXScriptSignal
Tham Số
Mẫu mã
Theo dõi kết thúc đầu vào trên một GuiObject
-- Để sử dụng sự kiện InputChanged, bạn phải chỉ định một GuiObject
local gui = script.Parent
-- Một hàm mẫu cung cấp nhiều trường hợp sử dụng cho các loại đầu vào của người dùng khác nhau
local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("Một phím đã được nhả! Phím:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Nút chuột trái đã được nhả tại", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Nút chuột phải đã được nhả tại", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("Một đầu vào từ màn hình cảm ứng đã được nhả tại", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("Một nút đã được nhả trên gamepad! Nút:", input.KeyCode)
end
end
gui.InputEnded:Connect(inputEnded)

MouseEnter
Các khả năng: UI
GuiObject.MouseEnter(
Tham Số
Mẫu mã
In Ấn Độ Nơi Con Chuột Vào một GuiObject
local guiObject = script.Parent
guiObject.MouseEnter:Connect(function(x, y)
print("Con trỏ chuột của người dùng đã vào GuiObject tại vị trí", x, ",", y)
end)

MouseLeave
Các khả năng: UI
GuiObject.MouseLeave(
Tham Số

MouseMoved
Các khả năng: UI
GuiObject.MouseMoved(
Tham Số

MouseWheelBackward
Các khả năng: UI
GuiObject.MouseWheelBackward(
Tham Số

MouseWheelForward
Các khả năng: UI
GuiObject.MouseWheelForward(
Tham Số

SelectionGained
Các khả năng: UI
GuiObject.SelectionGained():RBXScriptSignal
Mẫu mã
Xử lý lựa chọn GUI đã nhận
local guiObject = script.Parent
local function selectionGained()
print("Người dùng đã chọn nút này bằng gamepad.")
end
guiObject.SelectionGained:Connect(selectionGained)

SelectionLost
Các khả năng: UI
GuiObject.SelectionLost():RBXScriptSignal
Mẫu mã
Xử lý Mất Lựa Chọn GUI
local guiObject = script.Parent
local function selectionLost()
print("Người dùng không còn chọn cái này với tay cầm game của họ.")
end
guiObject.SelectionLost:Connect(selectionLost)

TouchLongPress
Các khả năng: UI
GuiObject.TouchLongPress(
touchPositions:{any}, state:Enum.UserInputState
Tham Số
touchPositions:{any}
Mẫu mã
Di chuyển phần tử UI với TouchLongPress
local frame = script.Parent
frame.Active = true
local dragging = false
local basePosition
local startTouchPosition
local borderColor3
local backgroundColor3
local function onTouchLongPress(touchPositions, state)
if state == Enum.UserInputState.Begin and not dragging then
-- Bắt đầu kéo
dragging = true
basePosition = frame.Position
startTouchPosition = touchPositions[1]
-- Tô màu cho frame để chỉ ra rằng việc kéo đang diễn ra
borderColor3 = frame.BorderColor3
backgroundColor3 = frame.BackgroundColor3
frame.BorderColor3 = Color3.new(1, 1, 1) -- Trắng
frame.BackgroundColor3 = Color3.new(0, 0, 1) -- Xanh
elseif state == Enum.UserInputState.Change then
local touchPosition = touchPositions[1]
local deltaPosition =
UDim2.new(0, touchPosition.X - startTouchPosition.X, 0, touchPosition.Y - startTouchPosition.Y)
frame.Position = basePosition + deltaPosition
elseif state == Enum.UserInputState.End and dragging then
-- Dừng kéo
dragging = false
frame.BorderColor3 = borderColor3
frame.BackgroundColor3 = backgroundColor3
end
end
frame.TouchLongPress:Connect(onTouchLongPress)

TouchPan
Các khả năng: UI
GuiObject.TouchPan(
touchPositions:{any}, totalTranslation:Vector2, velocity:Vector2, state:Enum.UserInputState
Tham Số
touchPositions:{any}
totalTranslation:Vector2
velocity:Vector2
Mẫu mã
Phần tử UI Panning
local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local basePosition
local function onTouchPan(_touchPositions, totalTranslation, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
basePosition = innerFrame.Position
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
innerFrame.Position = basePosition + UDim2.new(0, totalTranslation.X, 0, totalTranslation.Y)
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPan:Connect(onTouchPan)

TouchPinch
Các khả năng: UI
GuiObject.TouchPinch(
touchPositions:{any}, scale:number, velocity:number, state:Enum.UserInputState
Tham Số
touchPositions:{any}
scale:number
velocity:number
Mẫu mã
Phóng to / Kéo
local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local uiScale = Instance.new("UIScale")
uiScale.Parent = innerFrame
local baseScale
local function onTouchPinch(_touchPositions, scale, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
baseScale = uiScale.Scale
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
uiScale.Scale = baseScale * scale -- Lưu ý phép nhân ở đây
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPinch:Connect(onTouchPinch)

TouchRotate
Các khả năng: UI
GuiObject.TouchRotate(
touchPositions:{any}, rotation:number, velocity:number, state:Enum.UserInputState
Tham Số
touchPositions:{any}
rotation:number
velocity:number
Mẫu mã
Xoay Chạm
local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local baseRotation = innerFrame.Rotation
local function onTouchRotate(_touchPositions, rotation, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
baseRotation = innerFrame.Rotation
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
innerFrame.Rotation = baseRotation + rotation
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchRotate:Connect(onTouchRotate)

TouchSwipe
Các khả năng: UI
GuiObject.TouchSwipe(
swipeDirection:Enum.SwipeDirection, numberOfTouches:number
Tham Số
swipeDirection:Enum.SwipeDirection
numberOfTouches:number
Mẫu mã
Bảng chọn màu nhảy
local frame = script.Parent
frame.Active = true
-- Khoảng cách mà frame nên nhảy lên khi vuốt thành công
local BOUNCE_DISTANCE = 50
-- Trạng thái hiện tại của frame
local basePosition = frame.Position
local hue = 0
local saturation = 128
local function updateColor()
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, saturation / 256, 1)
end
local function onTouchSwipe(swipeDir, _touchCount)
-- Thay đổi BackgroundColor3 dựa vào hướng vuốt
local deltaPos
if swipeDir == Enum.SwipeDirection.Right then
deltaPos = UDim2.new(0, BOUNCE_DISTANCE, 0, 0)
hue = (hue + 16) % 255
elseif swipeDir == Enum.SwipeDirection.Left then
deltaPos = UDim2.new(0, -BOUNCE_DISTANCE, 0, 0)
hue = (hue - 16) % 255
elseif swipeDir == Enum.SwipeDirection.Up then
deltaPos = UDim2.new(0, 0, 0, -BOUNCE_DISTANCE)
saturation = (saturation + 16) % 255
elseif swipeDir == Enum.SwipeDirection.Down then
deltaPos = UDim2.new(0, 0, 0, BOUNCE_DISTANCE)
saturation = (saturation - 16) % 255
else
deltaPos = UDim2.new()
end
-- Cập nhật màu sắc và nhảy một chút
updateColor()
frame.Position = basePosition + deltaPos
frame:TweenPosition(basePosition, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 0.7, true)
end
frame.TouchSwipe:Connect(onTouchSwipe)
updateColor()

TouchTap
Các khả năng: UI
GuiObject.TouchTap(touchPositions:{any}):RBXScriptSignal
Tham Số
touchPositions:{any}
Mẫu mã
Chạm để chuyển đổi độ trong suốt
local frame = script.Parent
frame.Active = true
local function onTouchTap()
-- Chuyển đổi độ trong suốt nền
if frame.BackgroundTransparency > 0 then
frame.BackgroundTransparency = 0
else
frame.BackgroundTransparency = 0.75
end
end
frame.TouchTap:Connect(onTouchTap)

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.