เรียนรู้
Engine Class
GuiObject
ไม่สามารถสร้าง
ไม่สามารถเรียกดู

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
วิธีการ
TweenPosition(endPosition: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean
เลิกใช้แล้ว
TweenSize(endSize: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean
เลิกใช้แล้ว
TweenSizeAndPosition(endSize: UDim2,endPosition: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean
เลิกใช้แล้ว
สมาชิกที่ได้รับทอด
ได้รับทอดโดย
CanvasGroup, Frame, GuiButton, GuiLabel, ScrollingFrame,

เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
Active
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.Active:boolean
ตัวอย่างโค้ด
ปุ่มข้อความที่เปิดใช้งานแล้ว
-- วาง LocalScript นี้ใน TextButton (หรือ ImageButton)
local textButton = script.Parent
textButton.Text = "คลิกที่นี่"
textButton.Active = true
local function onActivated()
-- นี่ทำหน้าที่เหมือนไดบาวน์
textButton.Active = false
-- นับถอยหลังจาก 5
for i = 5, 1, -1 do
textButton.Text = "เวลา: " .. i
task.wait(1)
end
textButton.Text = "คลิกที่นี่"
textButton.Active = true
end
textButton.Activated:Connect(onActivated)

AnchorPoint
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.AnchorPoint:Vector2
ตัวอย่างโค้ด
สาธิต AnchorPoint
local guiObject = script.Parent
while true do
-- มุมซ้ายบน
guiObject.AnchorPoint = Vector2.new(0, 0)
guiObject.Position = UDim2.new(0, 0, 0, 0)
task.wait(1)
-- ด้านบน
guiObject.AnchorPoint = Vector2.new(0.5, 0)
guiObject.Position = UDim2.new(0.5, 0, 0, 0)
task.wait(1)
-- มุมขวาบน
guiObject.AnchorPoint = Vector2.new(1, 0)
guiObject.Position = UDim2.new(1, 0, 0, 0)
task.wait(1)
-- ด้านซ้าย
guiObject.AnchorPoint = Vector2.new(0, 0.5)
guiObject.Position = UDim2.new(0, 0, 0.5, 0)
task.wait(1)
-- ตรงกลาง
guiObject.AnchorPoint = Vector2.new(0.5, 0.5)
guiObject.Position = UDim2.new(0.5, 0, 0.5, 0)
task.wait(1)
-- ด้านขวา
guiObject.AnchorPoint = Vector2.new(1, 0.5)
guiObject.Position = UDim2.new(1, 0, 0.5, 0)
task.wait(1)
-- มุมซ้ายล่าง
guiObject.AnchorPoint = Vector2.new(0, 1)
guiObject.Position = UDim2.new(0, 0, 1, 0)
task.wait(1)
-- ด้านล่าง
guiObject.AnchorPoint = Vector2.new(0.5, 1)
guiObject.Position = UDim2.new(0.5, 0, 1, 0)
task.wait(1)
-- มุมขวาล่าง
guiObject.AnchorPoint = Vector2.new(1, 1)
guiObject.Position = UDim2.new(1, 0, 1, 0)
task.wait(1)
end

AutomaticSize
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.AutomaticSize:Enum.AutomaticSize
ตัวอย่างโค้ด
LocalScript ใน ScreenGui
-- อาร์เรย์ของป้ายชื่อ/แบบอักษร/ขนาดที่จะนำเสนอ
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 },
}
-- สร้างกรอบหลักที่มีขนาดอัตโนมัติ
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
-- เพิ่มเค้าโครงรายการ
local listLayout = Instance.new("UIListLayout")
listLayout.Padding = UDim.new(0, 5)
listLayout.Parent = parentFrame
-- ตั้งค่ามุมมนและช่องว่างเพื่อความสวยงาม
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
-- สร้างป้ายชื่อข้อความที่มีขนาดอัตโนมัติจากอาร์เรย์
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
-- ความสวยงาม
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
เลิกใช้แล้ว

BackgroundColor3
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.BackgroundColor3:Color3
ตัวอย่างโค้ด
กรอบสายรุ้ง
-- ใส่โค้ดนี้ใน LocalScript ในกรอบ
local frame = script.Parent
while true do
for hue = 0, 255, 4 do
-- HSV = สี, ความอิ่มตัว, ค่า
-- ถ้าเราหมุนจาก 0 ถึง 1 ซ้ำ ๆ เราจะได้รับสายรุ้ง!
frame.BorderColor3 = Color3.fromHSV(hue / 256, 1, 1)
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, 0.5, 0.8)
task.wait()
end
end

BackgroundTransparency
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.BackgroundTransparency:number

BorderColor
เลิกใช้แล้ว

BorderColor3
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.BorderColor3:Color3
ตัวอย่างโค้ด
ปุ่มไฮไลต์
-- ใส่ฉันไว้ใน GuiObject โดยเฉพาะอย่างยิ่งใน ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- สีเหลือง
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- สีดำ
end
-- เชื่อมต่อเหตุการณ์
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- สถานะเริ่มต้นของเราคือ "ไม่ได้วางหรือเลื่อนเมาส์"
onLeave()

BorderMode
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.BorderMode:Enum.BorderMode

BorderSizePixel
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.BorderSizePixel:number
ตัวอย่างโค้ด
ปุ่มไฮไลต์
-- ใส่ฉันไว้ใน GuiObject โดยเฉพาะอย่างยิ่งใน ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- สีเหลือง
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- สีดำ
end
-- เชื่อมต่อเหตุการณ์
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- สถานะเริ่มต้นของเราคือ "ไม่ได้วางหรือเลื่อนเมาส์"
onLeave()

ClipsDescendants
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.ClipsDescendants:boolean

Draggable
เลิกใช้แล้ว

GuiState
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.GuiState:Enum.GuiState

InputSink
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.InputSink:Enum.InputSink

Interactable
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.Interactable:boolean

LayoutOrder
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.LayoutOrder:number

NextSelectionDown
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.NextSelectionDown:GuiObject
ตัวอย่างโค้ด
การสร้างกริดการเลือก Gamepad
-- ตั้งค่ากริดการเลือก Gamepad โดยใช้โค้ดด้านล่าง
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
-- ขอบซ้าย
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- ขอบขวา
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- ด้านบน
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- ด้านล่าง
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- ทดสอบกริดการเลือก Gamepad โดยใช้โค้ดด้านล่าง
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
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.NextSelectionLeft:GuiObject
ตัวอย่างโค้ด
การสร้างกริดการเลือก Gamepad
-- ตั้งค่ากริดการเลือก Gamepad โดยใช้โค้ดด้านล่าง
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
-- ขอบซ้าย
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- ขอบขวา
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- ด้านบน
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- ด้านล่าง
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- ทดสอบกริดการเลือก Gamepad โดยใช้โค้ดด้านล่าง
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
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.NextSelectionRight:GuiObject
ตัวอย่างโค้ด
การสร้างกริดการเลือก Gamepad
-- ตั้งค่ากริดการเลือก Gamepad โดยใช้โค้ดด้านล่าง
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
-- ขอบซ้าย
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- ขอบขวา
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- ด้านบน
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- ด้านล่าง
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- ทดสอบกริดการเลือก Gamepad โดยใช้โค้ดด้านล่าง
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
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.NextSelectionUp:GuiObject
ตัวอย่างโค้ด
การสร้างกริดการเลือก Gamepad
-- ตั้งค่ากริดการเลือก Gamepad โดยใช้โค้ดด้านล่าง
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
-- ขอบซ้าย
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- ขอบขวา
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- ด้านบน
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- ด้านล่าง
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- ทดสอบกริดการเลือก Gamepad โดยใช้โค้ดด้านล่าง
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
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.Position:UDim2

Rotation
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.Rotation:number

Selectable
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.Selectable:boolean
ตัวอย่างโค้ด
การจำกัดการเลือก 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
-- เหตุการณ์ FocusLost และ FocusGained จะถูกเรียกใช้เพราะ textBox
-- เป็นชนิด TextBox
textBox.Focused:Connect(gainFocus)
textBox.FocusLost:Connect(loseFocus)

SelectionImageObject
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.SelectionImageObject:GuiObject

SelectionOrder
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.SelectionOrder:number

Size
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.Size:UDim2
ตัวอย่างโค้ด
แถบสุขภาพ
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- วางสคริปต์ลงใน LocalScript ที่
-- ถูกทำให้เป็นพ่อของเฟรมภายในเฟรม
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- สีดำ
-- ฟังก์ชันนี้จะถูกเรียกเมื่อสุขภาพของมนุษย์เปลี่ยนแปลง
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- เปลี่ยนขนาดของแถบภายใน
frame.Size = UDim2.new(percent, 0, 1, 0)
-- เปลี่ยนสีของแถบสุขภาพ
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- สีดำ
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- สีเหลือง
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- สีเขียว
end
end
-- ฟังก์ชันนี้จะถูกเรียกเมื่อผู้เล่นเกิดขึ้น
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- รูปแบบ: อัปเดตหนึ่งครั้งตอนนี้ จากนั้นทุกครั้งที่สุขภาพเปลี่ยนแปลง
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- เชื่อมต่อผู้ฟังการเกิดของเรา; เรียกใช้งานหากเกิดขึ้นแล้ว
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end

SizeConstraint
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.SizeConstraint:Enum.SizeConstraint

Transparency
เลิกใช้แล้ว

Visible
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.Visible:boolean
ตัวอย่างโค้ด
หน้าต่าง UI
local gui = script.Parent
local window = gui:WaitForChild("Window")
local toggleButton = gui:WaitForChild("ToggleWindow")
local closeButton = window:WaitForChild("Close")
local function toggleWindowVisbility()
-- สลับค่าจริงด้วยคำสั่ง `not`
window.Visible = not window.Visible
end
toggleButton.Activated:Connect(toggleWindowVisbility)
closeButton.Activated:Connect(toggleWindowVisbility)

ZIndex
อ่านพร้อมๆ กัน
ความสามารถ: UI
GuiObject.ZIndex:number

วิธีการ
TweenPosition
เลิกใช้แล้ว

TweenSize
เลิกใช้แล้ว

TweenSizeAndPosition
เลิกใช้แล้ว

เหตุการณ์
DragBegin
เลิกใช้แล้ว

DragStopped
เลิกใช้แล้ว

InputBegan
ความสามารถ: UI
GuiObject.InputBegan(input:InputObject):RBXScriptSignal
พารามิเตอร์
ตัวอย่างโค้ด
ติดตามการเริ่มต้นของการป้อนข้อมูลบน GuiObject
-- เพื่อใช้เหตุการณ์ InputBegan คุณต้องระบุ GuiObject
local gui = script.Parent
-- ฟังก์ชันตัวอย่างที่ให้กรณีการใช้งานหลายกรณีสำหรับประเภทต่าง ๆ ของการป้อนข้อมูลผู้ใช้
local function inputBegan(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("มีการกดปุ่มลง! ปุ่ม:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("ปุ่มเมาส์ด้านซ้ายถูกกดลงที่", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("ปุ่มเมาส์ด้านขวาถูกกดลงที่", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("มีการป้อนข้อมูลจากหน้าจอสัมผัสเริ่มต้นที่", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("มีการกดปุ่มบนเกมแพด! ปุ่ม:", input.KeyCode)
end
end
gui.InputBegan:Connect(inputBegan)

InputChanged
ความสามารถ: UI
GuiObject.InputChanged(input:InputObject):RBXScriptSignal
พารามิเตอร์
ตัวอย่างโค้ด
การสาธิต InputChanged ของ GuiObject
local UserInputService = game:GetService("UserInputService")
local gui = script.Parent
local function printMovement(input)
print("ตำแหน่ง:", input.Position)
print("การเคลื่อนไหว Delta:", input.Delta)
end
local function inputChanged(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
print("เมาส์ถูกเคลื่อนไหว!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
print("ล้อเมาส์ถูกเลื่อน!")
print("การเคลื่อนไหวของล้อ:", input.Position.Z)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.Thumbstick1 then
print("ทัชช์ที่ซ้ายถูกเคลื่อนไหว!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
print("ทัชช์ที่ขวาถูกเคลื่อนไหว!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
print("แรงที่ถูกกดบนทริกเกอร์ซ้ายมีการเปลี่ยนแปลง!")
print("แรงกด:", input.Position.Z)
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
print("แรงที่ถูกกดบนทริกเกอร์ขวามีการเปลี่ยนแปลง!")
print("แรงกด:", input.Position.Z)
end
elseif input.UserInputType == Enum.UserInputType.Touch then
print("นิ้วของผู้ใช้กำลังเคลื่อนที่บนหน้าจอ!")
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("การหมุนของอุปกรณ์มือถือของผู้ใช้มีการเปลี่ยนแปลง!")
print("ตำแหน่ง", rotCFrame.p)
print("การหมุน:", rot)
elseif input.UserInputType == Enum.UserInputType.Accelerometer then
print("การเร่งของอุปกรณ์มือถือของผู้ใช้มีการเปลี่ยนแปลง!")
printMovement(input)
end
end
gui.InputChanged:Connect(inputChanged)

InputEnded
ความสามารถ: UI
GuiObject.InputEnded(input:InputObject):RBXScriptSignal
พารามิเตอร์
ตัวอย่างโค้ด
ติดตามการสิ้นสุดของอินพุตบน GuiObject
-- เพื่อใช้เหตุการณ์ InputChanged คุณต้องระบุ GuiObject
local gui = script.Parent
-- ฟังก์ชันตัวอย่างที่ให้กรณีการใช้งานหลายประการสำหรับประเภทต่าง ๆ ของอินพุตของผู้ใช้
local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("ปุ่มถูกปล่อยแล้ว! คีย์:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("ปุ่มเมาส์ซ้ายถูกปล่อยที่", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("ปุ่มเมาส์ขวาถูกปล่อยที่", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("อินพุตจอสัมผัสถูกปล่อยที่", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("ปุ่มถูกปล่อยบนเกมแพด! ปุ่ม:", input.KeyCode)
end
end
gui.InputEnded:Connect(inputEnded)

MouseEnter
ความสามารถ: UI
GuiObject.MouseEnter(
พารามิเตอร์
ตัวอย่างโค้ด
การพิมพ์เมื่อเมาส์เข้ามาใน GuiObject
local guiObject = script.Parent
guiObject.MouseEnter:Connect(function(x, y)
print("เคอร์เซอร์เมาส์ของผู้ใช้ได้เข้ามาที่ GuiObject ที่ตำแหน่ง", x, ",", y)
end)

MouseLeave
ความสามารถ: UI
GuiObject.MouseLeave(
พารามิเตอร์

MouseMoved
ความสามารถ: UI
GuiObject.MouseMoved(
พารามิเตอร์

MouseWheelBackward
ความสามารถ: UI
GuiObject.MouseWheelBackward(
พารามิเตอร์

MouseWheelForward
ความสามารถ: UI
GuiObject.MouseWheelForward(
พารามิเตอร์

SelectionGained
ความสามารถ: UI
GuiObject.SelectionGained():RBXScriptSignal
ตัวอย่างโค้ด
การจัดการการเลือก GUI ที่ได้รับ
local guiObject = script.Parent
local function selectionGained()
print("ผู้ใช้ได้เลือกปุ่มนี้ด้วยเกมแพด。")
end
guiObject.SelectionGained:Connect(selectionGained)

SelectionLost
ความสามารถ: UI
GuiObject.SelectionLost():RBXScriptSignal
ตัวอย่างโค้ด
การจัดการการเลือก GUI ที่หายไป
local guiObject = script.Parent
local function selectionLost()
print("ผู้ใช้ไม่ได้เลือกสิ่งนี้ด้วยเกมแพดอีกต่อไป.")
end
guiObject.SelectionLost:Connect(selectionLost)

TouchLongPress
ความสามารถ: UI
GuiObject.TouchLongPress(
touchPositions:{any}, state:Enum.UserInputState
พารามิเตอร์
touchPositions:{any}
ตัวอย่างโค้ด
ย้าย UI Element ด้วยการกดนิ้วค้าง
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
-- เริ่มต้นการลาก
dragging = true
basePosition = frame.Position
startTouchPosition = touchPositions[1]
-- เปลี่ยนสีของเฟรมเพื่อแสดงว่ากำลังลากอยู่
borderColor3 = frame.BorderColor3
backgroundColor3 = frame.BackgroundColor3
frame.BorderColor3 = Color3.new(1, 1, 1) -- ขาว
frame.BackgroundColor3 = Color3.new(0, 0, 1) -- น้ำเงิน
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
-- หยุดการลาก
dragging = false
frame.BorderColor3 = borderColor3
frame.BackgroundColor3 = backgroundColor3
end
end
frame.TouchLongPress:Connect(onTouchLongPress)

TouchPan
ความสามารถ: UI
GuiObject.TouchPan(
touchPositions:{any}, totalTranslation:Vector2, velocity:Vector2, state:Enum.UserInputState
พารามิเตอร์
touchPositions:{any}
totalTranslation:Vector2
velocity:Vector2
ตัวอย่างโค้ด
องค์ประกอบ UI ที่ปรับพาน
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
ความสามารถ: UI
GuiObject.TouchPinch(
touchPositions:{any}, scale:number, velocity:number, state:Enum.UserInputState
พารามิเตอร์
touchPositions:{any}
scale:number
velocity:number
ตัวอย่างโค้ด
การปรับขนาดด้วยการบีบหรือดึง
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 -- สังเกตการคูณที่นี่
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPinch:Connect(onTouchPinch)

TouchRotate
ความสามารถ: UI
GuiObject.TouchRotate(
touchPositions:{any}, rotation:number, velocity:number, state:Enum.UserInputState
พารามิเตอร์
touchPositions:{any}
rotation:number
velocity:number
ตัวอย่างโค้ด
การหมุนแบบสัมผัส
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
ความสามารถ: UI
GuiObject.TouchSwipe(
swipeDirection:Enum.SwipeDirection, numberOfTouches:number
พารามิเตอร์
swipeDirection:Enum.SwipeDirection
numberOfTouches:number
ตัวอย่างโค้ด
ตัวเลือกสีที่เด้ง
local frame = script.Parent
frame.Active = true
-- ระยะที่เฟรมควรเด้งเมื่อมีการเลื่อนสำเร็จ
local BOUNCE_DISTANCE = 50
-- สถานะปัจจุบันของเฟรม
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)
-- เปลี่ยน BackgroundColor3 ตามทิศทางการเลื่อน
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
-- อัปเดตสีและทำให้เฟรมเด้งเล็กน้อย
updateColor()
frame.Position = basePosition + deltaPos
frame:TweenPosition(basePosition, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 0.7, true)
end
frame.TouchSwipe:Connect(onTouchSwipe)
updateColor()

TouchTap
ความสามารถ: UI
GuiObject.TouchTap(touchPositions:{any}):RBXScriptSignal
พารามิเตอร์
touchPositions:{any}
ตัวอย่างโค้ด
ปุ่มสลับความโปร่งใส
local frame = script.Parent
frame.Active = true
local function onTouchTap()
-- สลับความโปร่งใสของพื้นหลัง
if frame.BackgroundTransparency > 0 then
frame.BackgroundTransparency = 0
else
frame.BackgroundTransparency = 0.75
end
end
frame.TouchTap:Connect(onTouchTap)

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ