Tool

แสดงที่เลิกใช้งานแล้ว

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

เครื่องมือเป็นวัตถุที่วัตถุ Humanoid สามารถติดตั้งได้สำหรับผู้เล่นพวกเขาจะถูกจัดเก็บในวัตถุ Backpack ที่เป็นพ่อของวัตถุ Playerในเกมผู้เล่นอาจมีเครื่องมือหลายอย่างที่ปรากฏเป็นไอคอนที่ด้านล่างของหน้าจอการติดตั้งเครื่องมือจะย้ายมันจากกระเป๋าเป้สะพายหลังไปสู่รูปแบบ Player.Character ใน Workspaceโดยค่าเริ่มต้นเครื่องมือจะถูกจัดในมือขวาและมีจัดการอยู่ในนั้นซึ่งเป็นชื่อ Part ที่เรียกว่า "จัดการ" ภายใน (แม้ว่าหนึ่งจะไม่จำเป็นถ้า Tool.RequiresHandle ปิดอยู่)เครื่องมือที่จะถูกจัดให้กับผู้เล่นที่จะเกิดใหม่ควรจะถูกเก็บไว้ใน StarterPack

บนพีซีกดปุ่มตัวเลข (1, 2, 3...) จะติดตั้งเครื่องมือเครื่องมือที่ติดตั้งแล้วสามารถวางลงในพื้นที่ทำงานได้โดยการกด Backspaceขอแนะนำให้คุณปิด Tool.CanBeDropped เพื่อให้ไม่สามารถทิ้งเครื่องมือได้ ตาย เกิดใหม่ และทิ้งอีกครั้งเพื่อทำซ้ำเครื่องมือบนแผ่นเกม LB และ RB จะติดตั้งเครื่องมือคุณสามารถปิดการเปิดใช้งานผ่านการคลิกซ้าย (หรือการกระตุ้นด้านขวาบนบนคอนโซลเกม) โดยการตั้งค่า Tool.ManualActivationOnly บนการทำเช่นนั้นต้องการให้คุณโทรเรียกเปิดใช้งานตัวเองผ่านการป้อนข้อมูลของผู้ใช้รายอื่นในรูปแบบใดที่

เครื่องมือไม่ใช่วิธีเดียวในการจับภาพการป้อนข้อมูลของผู้ใช้คุณยังสามารถใช้ ContextActionService , UserInputService หรือ Player:GetMouse() ได้หากคุณต้องการเครื่องมือที่มีการดำเนินการหลายอย่าง เช่น กดปุ่มในขณะที่เครื่องมือติดตั้ง คุณควรใช้ ContextActionService's BindAction และ UnbindAction ในกิจกรรม Equipped และ Unequipped ตามลำดับใช้ LocalScript ส่งการดำเนินการเหล่านี้ไปยังเซิร์ฟเวอร์ผ่าน RemoteFunction ภายในเครื่องมือ

ตัวอย่างโค้ด

This code is meant to be placed in a Script within a Tool. It allows a player to spawn explosions by equipping the tool and clicking on the ground. It does so by defining a function, explode, which creates a non-deadly explosion at a given point. Then, it defines a function, onActivated, that runs when the tool is activated. Finally, it connects the Activated event of the tool to the onActivated function.

To test this code out, try creating a Tool and put a Part inside it. Name the Part "Handle". Put a Script inside the Tool next, and paste the code into it. Finally, put the Tool in the StarterPack.

Explode Tool Example

local tool = script.Parent
local function explode(point)
local e = Instance.new("Explosion")
e.DestroyJointRadiusPercent = 0 -- Make the explosion non-deadly
e.Position = point
e.Parent = workspace
end
local function onActivated()
-- Get the Humanoid that Activated the tool
local human = tool.Parent.Humanoid
-- Call explode with the current point the Humanoid is targetting
explode(human.TargetPoint)
end
tool.Activated:Connect(onActivated)

This code sample is for a Tool object with a Part named Handle. It detects when Humanoids other than the current holder hit the handle, and deals some damage to them. In addition, when the Tool is activated, it triggers a slash animation in the default character animation scripts. Try out this script by creating a Tool object in the StarterPack. Put a Part inside it, and name it Handle. Paste this code into a Script inside the Tool, then try slashing at another Humanoid!

Sword Tool Example

local tool = script.Parent
local function onTouch(partOther)
-- First, try to see if the part we touched was part of a Humanoid
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
-- Ignore touches by non-humanoids
if not humanOther then
return
end
-- Ignore touches by the Humanoid carrying the sword
if humanOther.Parent == tool.Parent then
return
end
humanOther:TakeDamage(5)
end
-- Trigger a slash animation
local function slash()
-- Default character scripts will listen for a "toolanim" StringValue
local value = Instance.new("StringValue")
value.Name = "toolanim"
value.Value = "Slash" -- try also: Lunge
value.Parent = tool
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

สรุป

คุณสมบัติ

  • อ่านพร้อมๆ กัน

    ควบคุมว่าผู้เล่นสามารถวางเครื่องมือได้หรือไม่

  • อ่านพร้อมๆ กัน

    เกี่ยวข้องกับว่าเครื่องมือสามารถใช้ได้หรือไม่

  • อ่านพร้อมๆ กัน

    เก็บคุณสมบัติ "การจับ" ของเครื่องมือเป็นหนึ่ง CFrame

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    แทนค่า R02 , R12 และ R22 ของค่าการหมุนของแมทริคซึ่งจับได้ CFrame

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ความเคลื่อนที่ตำแหน่งของแมทริคการเชื่อมต่อของเครื่องมือ

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    แทนค่า R00 , R10 และ R20 ของค่าการหมุนของแมทริคซึ่งจับได้ CFrame

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    แทนค่า R01 , R11 และ R21 ของค่าการหมุนของแมทริคซึ่งจับได้ CFrame

  • อ่านพร้อมๆ กัน

    คุณสมบัติ ManualActivationOnly ควบคุมว่า Tool สามารถเปิดใช้งานได้โดยไม่ต้องดําเนินการ Tool:Activate()

  • อ่านพร้อมๆ กัน

    กำหนดว่าฟังก์ชัน Tool ที่ไม่มีจัดการจะเป็นหรือไม่

  • อ่านพร้อมๆ กัน

    ควบคุมข้อความที่แสดงเมื่อเมาส์ของผู้เล่นเลื่อนเหนือเครื่องมือในกระเป๋าเป้สะพายหลังของพวกเขา

คุณสมบัติรับทอดมาจากBackpackItem
  • TextureId:ContentId
    อ่านพร้อมๆ กัน

    ไอคอนเทกเจอร์ที่แสดงสำหรับเครื่องมือในกระเป๋าเป้ของผู้เล่น

คุณสมบัติรับทอดมาจากModel
  • การรักษาความปลอดภัยของปลั๊กอิน
    อ่านพร้อมๆ กัน

    ตั้งระดับรายละเอียดบนโมเดลสำหรับประสบการณ์ที่มีการสตรีมตัวอย่างเปิดใช้งาน

  • อ่านพร้อมๆ กัน

    ควบคุมพฤติกรรมการสตรีมรูปแบบบน Models เมื่อการสตรีมตัวอย่างถูกเปิดใช้งาน

  • อ่านพร้อมๆ กัน

    ส่วนหลักของ Model หรือ nil ตั้งค่า

  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน

    คุณสมบัติสำหรับเอดิเตอร์เท่านั้นที่ใช้เพื่อขยายโมเดลรอบจุดศูนย์กลางของมัน การตั้งค่าคุณสมบัตินี้จะเคลื่อนย้ายเครื่องชั่งเหมือนว่า Model/ScaleTo ถูกเรียกใช้บนมัน

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    กำหนดตำแหน่งที่ศูนย์กลางของ ซึ่งไม่ได้มีชุด ตั้งอยู่

คุณสมบัติรับทอดมาจากPVInstance
  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน
  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน

วิธีการ

  • จำลองการเปิดใช้งานของ Tool

  • จำลองการปิดใช้งานของ Tool

วิธีการรับทอดมาจากModel
  • AddPersistentPlayer(playerInstance : Player):()

    ตั้งค่าโมเดลนี้ให้เป็นถาวรสำหรับผู้เล่นที่ระบุModel.ModelStreamingMode ต้องตั้งค่าเป็น PersistentPerPlayer เพื่อให้พฤติกรรมเปลี่ยนแปลงเนื่องจากการเพิ่ม

  • คืนคำอธิบายของระดับที่มีส่วนประกอบทั้งหมดของโมเดล

  • คืนขนาดของกล่องล้อมรอบขนาดเล็กที่มีทั้งหมด BaseParts ใน Model สอดคล้องกับ Model.PrimaryPart หากกำหนดไว้

  • คืนวัตถุทั้งหมด Player ที่วัตถุรูปแบบนี้มีอยู่อย่างถาวรพฤติกรรมแตกต่างกันขึ้นอยู่กับว่าวิธีนี้ถูกเรียกจาก Script หรือ LocalScript หรือไม่

  • ส่งคืนเครื่องชั่งหลักของโมเดลซึ่งเริ่มต้นที่ 1 สำหรับโมเดลที่สร้างขึ้นใหม่และจะเปลี่ยนเมื่อมันถูกขยายผ่าน Model/ScaleTo

  • MoveTo(position : Vector3):()

    ย้าย PrimaryPart ไปยังตำแหน่งที่กำหนด หากส่วนหลักไม่ได้ระบุไว้ ส่วนรากของโมเดลจะถูกใช้

  • RemovePersistentPlayer(playerInstance : Player):()

    ทำให้โมเดลนี้ไม่ยังคงอยู่สำหรับผู้เล่นที่ระบุแล้วModel.ModelStreamingMode ต้องตั้งค่าเป็น PersistentPerPlayer เพื่อให้พฤติกรรมเปลี่ยนแปลงเนื่องจากการลบ

  • ScaleTo(newScaleFactor : number):()

    ตั้งตัวคูณขนาดของโมเดลโดยปรับขนาดและตำแหน่งของโอนุการทั้งหมดเพื่อให้มีตัวคูณขนาดเท่ากับขนาดและตำแหน่งเดิมเมื่อตัวคูณขนาดอยู่ที่ 1

  • TranslateBy(delta : Vector3):()

    เปลี่ยน Model โดยออฟเซ็ตที่กำหนด Vector3 เพื่อรักษาการจัดตำแหน่งของรูปแบบหากอีก BasePart หรือ Terrain มีอยู่แล้วในตำแหน่งใหม่แล้ว ตัว Model จะซ้อนบนวัตถุที่กล่าวถึง

วิธีการรับทอดมาจากPVInstance
  • เขียนพร้อมๆ กัน

    รับจุดศูนย์กลางของ PVInstance .

  • PivotTo(targetCFrame : CFrame):()

    เปลี่ยน PVInstance พร้อมกับบรรดาลูกหลานทั้งหมดของมัน PVInstances ทำให้จุดศูนย์กลางอยู่ที่ตําแหน่งที่ระบุแล้ว CFrame

อีเวนต์

  • จะเกิดไฟไหม้เมื่อผู้เล่นคลิกในขณะที่เครื่องมือถูกติดตั้ง

  • เกิดไฟไหม้เมื่อผู้เล่นปล่อยการคลิกขณะที่เครื่องมือถูกติดตั้งและเปิดใช้งาน

  • จะเกิดไฟไหม้เมื่อเครื่องมือถูกติดตั้ง

  • จะเกิดไฟไหม้เมื่อเครื่องมือถูกถอดออก

คุณสมบัติ

CanBeDropped

อ่านพร้อมๆ กัน

คุณสมบัติ CanBeDropped ควบคุมว่าผู้เล่นสามารถวาง Tool ได้หรือไม่

ถ้าเป็นจริงเมื่อกดปุ่มลบหลัง, เครื่องมือจะถูกผูกกับ Workspace และถูกลบออกจากผู้เล่น Backpackหากเป็นเท็จ จะไม่มีอะไรเกิดขึ้นเมื่อกดปุ่มย้อนกลับและเครื่องมือจะยังคงติดตั้งอยู่

Enabled

อ่านพร้อมๆ กัน

คุณสมบัติ เปิดใช้งาน เกี่ยวข้องกับว่า Tool สามารถใช้งานได้หรือไม่นี่มีประโยชน์หากคุณต้องการป้องกันไม่ให้ผู้เล่นใช้เครื่องมือ แต่ไม่ต้องการลบมันออกจากพวกเขา Backpack

เมื่อตั้งค่าเป็น true ผู้เล่นสามารถใช้เครื่องมือได้เมื่อตั้งค่าเป็น false เครื่องมือจะถูกปิดใช้งานและผู้เล่นไม่สามารถใช้งานได้; ซึ่งทำให้เครื่องมือไม่ถูกเปิดใช้งานหรือปิดใช้งานโดยวิธี Tool:Activate() และ Tool:Deactivate() และป้องกันไม่ให้เหตุการณ์ Tool.Activated และ Tool.Deactivated เกิดขึ้น

ตัวอย่างโค้ด

The code sample below creates Tool in the local player's Backpack that increases their JumpPower from 50 to 150 for 5 seconds.

This example uses the tool's Tool.Enabled property as a debounce by setting the property to true when the player jumps and back to false after the 5 second duration.

Unequipping the tool also stops the player from super jumping by changing the JumpPower back to 50.

Superjump Tool

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

อ่านพร้อมๆ กัน

คุณสมบัติ Grip เก็บคุณสมบัติ "การจับ" ของเครื่องมือเป็นค่าเดียว CFrameคุณสมบัติเหล่านี้จะบอกตำแหน่งที่ผู้เล่นถือเครื่องมือและรวมถึง GripUp , GripRight , GripForward และ GripPos

ตัวอย่างโค้ด

The code below insert's a Tool named Stick into the local player's Class.BackPack. When the player activates the tool, the code prints the values of the tool's grip properties.

Grip Stick

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) -- Brown
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

GripForward

ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน

หนึ่งในคุณสมบัติที่ระบุทิศทางของเครื่องมือในมือของตัวละครนี่เป็นตัวแทนของ R02 , R12 และ R22 ค่าของแมทริคการหมุนของจับ CFrame

คุณสมบัติเครื่องมืออื่นๆ ที่ควบคุมวิธีที่ตัวละครถือเครื่องมือรวมถึง Tool.GripUp , Tool.GripRight และ Tool.GripPosคุณสมบัติเหล่านี้ทั้งหมดจะถูกจัดเก็บในคุณสมบัติเดียว CFrame ในคุณสมบัติ Tool.Grip

ตัวอย่างโค้ด

The code below insert's a Tool named Stick into the local player's Class.BackPack. When the player activates the tool, the code prints the values of the tool's grip properties.

Grip Stick

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) -- Brown
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

GripPos

ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน

คุณสมบัตินี้ควบคุมการเลื่อนตำแหน่งของแมทริคการเชื่อมต่อของเครื่องมือเป็นหนึ่งในหลายคุณสมบัติที่ใช้เพื่อกำหนดตำแหน่งที่ตัวละครผู้เล่นถือเครื่องมือ

คุณสมบัติอื่นๆ ที่ควบคุมวิธีที่ตัวละครถือเครื่องมือรวมถึง Tool.GripUp , Tool.GripRight และ Tool.GripForwardคุณสมบัติเหล่านี้ทั้งหมดจะถูกจัดเก็บในคุณสมบัติเดียว CFrame ในคุณสมบัติ Tool.Grip

ตัวอย่างโค้ด

The code below insert's a Tool named Stick into the local player's Class.BackPack. When the player activates the tool, the code prints the values of the tool's grip properties.

Grip Stick

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) -- Brown
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

GripRight

ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน

หนึ่งในคุณสมบัติที่ระบุทิศทางของเครื่องมือในมือของตัวละครนี่เป็นตัวแทนของ R00 , R10 และ R20 ค่าของแมทริคการหมุนของจับ CFrame

คุณสมบัติเครื่องมืออื่นๆ ที่ควบคุมวิธีที่ตัวละครถือเครื่องมือรวมถึง Tool.GripUp , Tool.GripForward และ Tool.GripPosคุณสมบัติเหล่านี้ทั้งหมดจะถูกจัดเก็บในคุณสมบัติเดียว CFrame ในคุณสมบัติ Tool.Grip

ตัวอย่างโค้ด

The code below insert's a Tool named Stick into the local player's Class.BackPack. When the player activates the tool, the code prints the values of the tool's grip properties.

Grip Stick

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) -- Brown
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

GripUp

ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน

หนึ่งในคุณสมบัติที่ระบุทิศทางของเครื่องมือในมือของตัวละครนี่เป็นตัวแทนของ R01 , R11 และ R21 ค่าของแมทริคการหมุนของจับ CFrame

คุณสมบัติเครื่องมืออื่นๆ ที่ควบคุมวิธีที่ตัวละครถือเครื่องมือรวมถึง Tool.GripRight , Tool.GripForward และ Tool.GripPosคุณสมบัติเหล่านี้ทั้งหมดจะถูกจัดเก็บในคุณสมบัติเดียว CFrame ในคุณสมบัติ Tool.Grip

ตัวอย่างโค้ด

The code below insert's a Tool named Stick into the local player's Class.BackPack. When the player activates the tool, the code prints the values of the tool's grip properties.

Grip Stick

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) -- Brown
tool.Activated:Connect(function()
print(tool.Grip)
print(tool.GripUp)
print(tool.GripRight)
print(tool.GripForward)
print(tool.GripPos)
end)

ManualActivationOnly

อ่านพร้อมๆ กัน

คุณสมบัติการเปิดใช้งานแบบด่วนเท่านั้นจะควบคุมว่า Tool สามารถเปิดใช้งานได้โดยไม่ต้องดําเนินการตามตัวอักษร Tool:Activate() ในสคริปต์

เมื่อตั้งค่าเป็นจริง เครื่องมือจะยิง Tool.Activated เฉพาะเมื่อ Tool:Activate() ถูกเรียก ซึ่งยังปิดการใช้งานฟังก์ชัน ContextActionService:BindActivate()

เมื่อตั้งค่าเป็น false การคลิกเมาส์ (เมื่อมีเครื่องมือติดตั้ง) จะยิง Tool.Activated เช่นกัน

ตัวอย่างโค้ด

The code sample below creates Tool in the local player's Backpack that increases their WalkSpeed from 16 to 30 for 5 seconds.

This example uses the tool's Tool.ManualActivationOnly property as a debounce by setting the property to true when the player begins sprinting and to false when the player stops sprinting. As a result, when the player is sprinting, the tool cannot be re-activated.

Unequipping the tool also stops the player from sprinting by changing the WalkSpeed to 16.

Sprint Tool

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

อ่านพร้อมๆ กัน

คุณสมบัตินี้กำหนดว่าฟังก์ชัน Tool โดยไม่มีจัดการจะเป็นหรือไม่

เครื่องมือมีจัดการเมื่อมันมีส่วนลูกที่ชื่อว่า จัดการ เครื่องมือที่มีจัดการมักต้องให้ผู้เล่นสวมใส่พวกเขาเพื่อถือวัตถุเพื่อใช้พวกเขา เช่น อาวุธเครื่องมือที่ไม่มีจัดการมักไม่ต้องการให้ผู้เล่นสวมใส่พวกมันเพื่อถือสิ่งใดเพื่อใช้พวกมัน เช่น เครื่องมือ "บิน" หรือ "อัญเชิญ"

เมื่อตั้งค่าเป็น true เครื่องมือจะทำงานได้เฉพาะด้วยจัดการเท่านั้น เมื่อตั้งค่าเป็น false เครื่องมือจะทำงานได้แม้ไม่มีจัดการ

ToolTip

อ่านพร้อมๆ กัน

คุณสมบัติ ToolTip ควบคุมข้อความที่จะแสดงเมื่อผู้เล่น Mouse เลื่อนเมาส์ไปเหนือ Tool ใน Backpack ของพวกเขา

โดยทั่วไปค่าของคุณสมบัตินี้ควรอธิบายสิ่งที่เครื่องมือเป็นหรือการใช้งานตัวอย่างเช่นสำหรับเครื่องมือพลั่วคุณอาจเลือกที่จะตั้งค่า ToolTip เป็น:


tool.ToolTip = "Shovel"

or


tool.ToolTip = "Use to dig"

or


tool.ToolTip = "Shovel - Use to dig"

วิธีการ

Activate

()

ฟังก์ชันนี้จำลองการเปิดใช้งานของ Tool เครื่องมือจะต้องติดตั้งเพื่อให้ฟังก์ชันนี้ทำงาน


ส่งค่ากลับ

()

ตัวอย่างโค้ด

The code below creates a Tool in the local player's Backpack that turns the player invisible when activated and visible when deactivated.

When equipped, the script simulates the tool being activated and turns the player invisible for 3 seconds and then simulates the tool being deactivated. Holding the left mouse button down turns the player invisible for up to 3 seconds, with a cooldown period of 1 second, or until the player releases their left mouse button.

Invisibility Tool

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local tool = Instance.new("Tool")
tool.Name = "Invisibility Tool"
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

()

ฟังก์ชันนี้จำลองการปิดใช้งานของ Tool เครื่องมือต้องมีอุปกรณ์เพื่อให้ฟังก์ชันนี้ทำงานได้


ส่งค่ากลับ

()

ตัวอย่างโค้ด

The code below creates a Tool in the local player's Backpack that turns the player invisible when activated and visible when deactivated.

When equipped, the script simulates the tool being activated and turns the player invisible for 3 seconds and then simulates the tool being deactivated. Holding the left mouse button down turns the player invisible for up to 3 seconds, with a cooldown period of 1 second, or until the player releases their left mouse button.

Invisibility Tool

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local tool = Instance.new("Tool")
tool.Name = "Invisibility Tool"
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

อีเวนต์นี้จะเกิดขึ้นเมื่อผู้เล่นคลิกในขณะที่ Tool ถูกติดตั้งมันไม่ได้ ไม่ ถูกยิงหากแป้น Ctrl กดในระหว่างการคลิก

อีเวนต์นี้มักใช้เพื่อดำเนินการตอนที่ผู้เล่นใช้เครื่องมือ เช่น เพื่อเปิดตัวจรวดจากเครื่องมือปืนยิงจรวด

รหัสLocalScript จะสร้างเครื่องมือใน Backpack ของผู้เล่นท้องถิ่นและพิมพ์ "เครื่องมือถูกเปิดใช้งาน" เมื่อผู้เล่นคลิกในขณะที่เครื่องมือที่สร้างขึ้นถูกติดตั้ง


local Players = game:GetService("Players")
local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.Parent = Players.LocalPlayer.Backpack
function onActivation()
print("Tool activated")
end
tool.Activated:Connect(onActivation)

Deactivated

อีเวนต์นี้จะเกิดขึ้นเมื่อผู้เล่นปล่อยการคลิกขณะที่ Tool ถูกติดตั้งและเปิดใช้งานมักใช้เพื่อดำเนินการเมื่อผู้เล่นหยุดใช้เครื่องมือ

รหัสLocalScript จะสร้างเครื่องมือใน Backpack ของผู้เล่นท้องถิ่นและพิมพ์ "เครื่องมือถูกปิดใช้งาน" เมื่อผู้เล่นปล่อยการคลิกของพวกเขาในขณะที่เครื่องมือถูกติดตั้งและเปิดใช้งาน


local Players = game:GetService("Players")
local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.Parent = Players.LocalPlayer.Backpack
function toolDeactivated()
print("Tool deactivated")
end
tool.Deactivated:Connect(toolDeactivated)

Equipped

อีเวนต์นี้จะเกิดขึ้นเมื่อผู้เล่นสวมใส่ Tool (นำออกจาก Backpack )

สิ่งตรงกันข้ามของเหตุการณ์นี้, Tool.Unequipped , สามารถใช้เพื่อกำหนดเวลาที่ผู้เล่นถอดอุปกรณ์โดยวางไว้ในกระเป๋าเป้สะพายหลัง

โปรดทราบว่าอีเวนต์นี้ไม่ได้ ไม่ ยิงเมื่อ Tool.RequiresHandle เปิดใช้งานและไม่มีจัดการปรากฏ

พารามิเตอร์

mouse: Mouse

เมาส์ของผู้เล่น


ตัวอย่างโค้ด

The example shown below will print "A tool was equipped" each time the tool is equipped by the player. Please note that the below example assumes that you've already defined what "Tool" is.

Print when a Player Equips a Tool

local Tool = script.Parent
local function onEquipped(_mouse)
print("The tool was equipped")
end
Tool.Equipped:Connect(onEquipped)

Unequipped

อีเวนต์นี้จะเกิดขึ้นเมื่อผู้เล่นถอด Tool (วางไว้ใน Backpack )

สิ่งที่ตรงกันข้ามกับเหตุการณ์นี้, Tool.Equipped , สามารถใช้เพื่อกำหนดเวลาที่ผู้เล่นใช้เครื่องมือโดยนำออกจากกระเป๋าเป้สะพายหลัง

โปรดทราบว่าอีเวนต์นี้ไม่ได้ ไม่ ยิงเมื่อ Tool.RequiresHandle เปิดใช้งานและไม่มีจัดการปรากฏ