เรียนรู้
Engine Class
Tool

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


สรุป
วิธีการ
สมาชิกที่ได้รับทอด
ได้รับทอดโดย
ตัวอย่างโค้ด
ตัวอย่างเครื่องมือระเบิด
local tool = script.Parent
local function explode(point)
local e = Instance.new("Explosion")
e.DestroyJointRadiusPercent = 0 -- ทำให้การระเบิดไม่เป็นอันตราย
e.Position = point
e.Parent = workspace
end
local function onActivated()
-- รับ Humanoid ที่เปิดใช้งานเครื่องมือ
local human = tool.Parent.Humanoid
-- เรียกใช้ explode ด้วยจุดที่ Humanoid กำลังเล็งอยู่
explode(human.TargetPoint)
end
tool.Activated:Connect(onActivated)
ตัวอย่างเครื่องมือดาบ
local tool = script.Parent
local function onTouch(partOther)
-- ก่อนอื่น ลองดูก่อนว่าชิ้นส่วนที่เราทำการสัมผัสเป็นส่วนหนึ่งของ Humanoid หรือไม่
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
-- ไม่สนใจการสัมผัสจากผู้ที่ไม่ใช่มนุษย์
if not humanOther then
return
end
-- ไม่สนใจการสัมผัสจาก Humanoid ที่ถือดาบ
if humanOther.Parent == tool.Parent then
return
end
humanOther:TakeDamage(5)
end
-- เรียกใช้อนิเมชันการฟัน
local function slash()
-- สคริปต์ตัวละครเริ่มต้นจะฟังสำหรับ "toolanim" StringValue
local value = Instance.new("StringValue")
value.Name = "toolanim"
value.Value = "Slash" -- ลองใช้: Lunge
value.Parent = tool
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
CanBeDropped
อ่านพร้อมๆ กัน
ความสามารถ: Input
Tool.CanBeDropped:boolean

Enabled
อ่านพร้อมๆ กัน
ความสามารถ: Input
การเข้าถึงการจำลองสถานการณ์
Tool.Enabled:boolean
ตัวอย่างโค้ด
เครื่องมือซุปเปอร์จัมพ์
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local tool = Instance.new("Tool")
tool.Name = "SuperJump"
tool.RequiresHandle = false
tool.Parent = player.Backpack
function toolActivated()
humanoid.JumpPower = 150
tool.Enabled = false
task.wait(5)
tool.Enabled = true
humanoid.JumpPower = 50
end
tool.Activated:Connect(toolActivated)
tool.Unequipped:Connect(function()
humanoid.JumpPower = 50
end)

Grip
อ่านพร้อมๆ กัน
ความสามารถ: Input
การเข้าถึงการจำลองสถานการณ์
Tool.Grip:CFrame
ตัวอย่างโค้ด
ที่จับ
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local tool = Instance.new("Tool")
tool.Name = "Stick"
tool.Parent = player.Backpack
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Parent = tool
handle.Size = Vector3.new(0.1, 3, 0.1)
handle.Color = Color3.fromRGB(108, 88, 75) -- สีน้ำตาล
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

GripForward
ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: Input
Tool.GripForward:Vector3
ตัวอย่างโค้ด
ที่จับ
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local tool = Instance.new("Tool")
tool.Name = "Stick"
tool.Parent = player.Backpack
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Parent = tool
handle.Size = Vector3.new(0.1, 3, 0.1)
handle.Color = Color3.fromRGB(108, 88, 75) -- สีน้ำตาล
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

GripPos
ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: Input
Tool.GripPos:Vector3
ตัวอย่างโค้ด
ที่จับ
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local tool = Instance.new("Tool")
tool.Name = "Stick"
tool.Parent = player.Backpack
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Parent = tool
handle.Size = Vector3.new(0.1, 3, 0.1)
handle.Color = Color3.fromRGB(108, 88, 75) -- สีน้ำตาล
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

GripRight
ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: Input
Tool.GripRight:Vector3
ตัวอย่างโค้ด
ที่จับ
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local tool = Instance.new("Tool")
tool.Name = "Stick"
tool.Parent = player.Backpack
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Parent = tool
handle.Size = Vector3.new(0.1, 3, 0.1)
handle.Color = Color3.fromRGB(108, 88, 75) -- สีน้ำตาล
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

GripUp
ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: Input
Tool.GripUp:Vector3
ตัวอย่างโค้ด
ที่จับ
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local tool = Instance.new("Tool")
tool.Name = "Stick"
tool.Parent = player.Backpack
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Parent = tool
handle.Size = Vector3.new(0.1, 3, 0.1)
handle.Color = Color3.fromRGB(108, 88, 75) -- สีน้ำตาล
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

ManualActivationOnly
อ่านพร้อมๆ กัน
ความสามารถ: Input
Tool.ManualActivationOnly:boolean
ตัวอย่างโค้ด
เครื่องมือวิ่ง
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local tool = Instance.new("Tool")
tool.Name = "Sprint"
tool.RequiresHandle = false
tool.Parent = player:WaitForChild("Backpack")
function toolActivated()
humanoid.WalkSpeed = 30
tool.ManualActivationOnly = true
task.wait(5)
tool.ManualActivationOnly = false
humanoid.WalkSpeed = 16
end
tool.Activated:Connect(toolActivated)
tool.Unequipped:Connect(function()
humanoid.WalkSpeed = 16
end)

RequiresHandle
อ่านพร้อมๆ กัน
ความสามารถ: Input
Tool.RequiresHandle:boolean

ToolTip
อ่านพร้อมๆ กัน
ความสามารถ: Input
Tool.ToolTip:string

วิธีการ
Activate
ความสามารถ: Input
Tool:Activate():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
เครื่องมือหายตัว
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local tool = Instance.new("Tool")
tool.Name = "เครื่องมือหายตัว"
tool.RequiresHandle = false
tool.Parent = player.Backpack
local invisible = false
local function toolActivated()
if invisible then
return
end
invisible = true
for _, bodypart in pairs(character:GetChildren()) do
if bodypart:IsA("MeshPart") or bodypart:IsA("Part") then
bodypart.Transparency = 1
end
end
task.wait(3)
tool:Deactivate()
task.wait(1)
invisible = false
end
local function toolDeactivated()
if not invisible then
return
end
for _, bodypart in pairs(character:GetChildren()) do
if bodypart.Name ~= "HumanoidRootPart" then
if bodypart:IsA("MeshPart") or bodypart:IsA("Part") then
bodypart.Transparency = 0
end
end
end
end
local function toolEquipped()
tool:Activate()
end
tool.Equipped:Connect(toolEquipped)
tool.Activated:Connect(toolActivated)
tool.Deactivated:Connect(toolDeactivated)
tool.Unequipped:Connect(toolDeactivated)

Deactivate
ความสามารถ: Input
Tool:Deactivate():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
เครื่องมือหายตัว
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local tool = Instance.new("Tool")
tool.Name = "เครื่องมือหายตัว"
tool.RequiresHandle = false
tool.Parent = player.Backpack
local invisible = false
local function toolActivated()
if invisible then
return
end
invisible = true
for _, bodypart in pairs(character:GetChildren()) do
if bodypart:IsA("MeshPart") or bodypart:IsA("Part") then
bodypart.Transparency = 1
end
end
task.wait(3)
tool:Deactivate()
task.wait(1)
invisible = false
end
local function toolDeactivated()
if not invisible then
return
end
for _, bodypart in pairs(character:GetChildren()) do
if bodypart.Name ~= "HumanoidRootPart" then
if bodypart:IsA("MeshPart") or bodypart:IsA("Part") then
bodypart.Transparency = 0
end
end
end
end
local function toolEquipped()
tool:Activate()
end
tool.Equipped:Connect(toolEquipped)
tool.Activated:Connect(toolActivated)
tool.Deactivated:Connect(toolDeactivated)
tool.Unequipped:Connect(toolDeactivated)

เหตุการณ์
Activated
ความสามารถ: Input
Tool.Activated():RBXScriptSignal

Deactivated
ความสามารถ: Input
Tool.Deactivated():RBXScriptSignal

Equipped
ความสามารถ: Input
Tool.Equipped(mouse:Mouse):RBXScriptSignal
พารามิเตอร์
mouse:Mouse
ตัวอย่างโค้ด
พิมพ์เมื่อผู้เล่นสวมอุปกรณ์
local Tool = script.Parent
local function onEquipped(_mouse)
print("อุปกรณ์ถูกสวมใส่")
end
Tool.Equipped:Connect(onEquipped)

Unequipped
ความสามารถ: Input
Tool.Unequipped():RBXScriptSignal

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