Tool

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

ツールは、 Humanoid オブジェクトが装備できるオブジェクトです。ツールは、プレイヤーにはスクリーンの下に表示される Class.

デスクトップで、数字キー (1、2、3...) を押すとツールを装備します。装備されたツールはワークスペースにドロップするために [バックスペース] を�

ツールはユーザーの入力をキャプチャする唯一の方法ではありません。ContextActionService およびUserInputService イベント

コードサンプル

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)

概要

プロパティ

  • 並列読み取り

    プレイヤーがツールをドロップできるかどうかを制御します。

  • 並列読み取り

    ツールが使用可能かどうかに関するレベル。

  • 並列読み取り

    ツールの「グリップ」プロパティを 1つの CFrame に保存します。

  • 非表示
    複製されていません
    並列読み取り

    グリップの R02R12 、および R22 の値を表示します。 1>Datatype.CFrame1> ローテーションマトリックスのグリップ。

  • 非表示
    複製されていません
    並列読み取り

    ツールの接合マトリックスの位置オフセット。

  • 非表示
    複製されていません
    並列読み取り

    グリップの R00R10 、および R20 の値を表示します。 1>Datatype.CFrame1> 回転マトリックスマットリックスマットリックスマットリックスマットリックスマットリックスマットリックスマットリックスマットリックスマットリックスマットリックスマットリックスマットリックスマットリック

  • 非表示
    複製されていません
    並列読み取り

    グリップの R01R11 、および R21 の値を表示します。

  • 並列読み取り

    ManualActivationOnly プロパティは、 Tool を実行しないで Class.Tool:Activate() できるかどうかを制御します。

  • 並列読み取り

    Class.Tool の機能をハンドルなしで使用できるかどうかを決定します。

  • 並列読み取り

    プレイヤーのマウスがバックパックのツールにあるときに表示されるメッセージをコントロールします。

BackpackItem から継承した プロパティ
  • TextureId:ContentId
    並列読み取り

    プレイヤーのバックパックに表示されるツールのテクスチャアイコン。

Model から継承した プロパティ
  • プラグインのセキュリティ
    並列読み取り

    インスタンスストリーミングを有効にしたエクスペリエンスの詳細レベルを設定します。

  • インスタンスストリーミングが有効になっているときに Models のモデルストリーミング動作を制御します。

  • 並列読み取り

    Class.Model または nil が明示的に設定する定されていない場合のメイン部分。

  • 複製されていません
    スクリプト作成できません
    並列読み取り

    モデルのピボットの周りにモデルをスケールするための編集者専用プロパティ。このプロパティを設定すると、スケールが Model/ScaleTo が呼び出されたように移動します。

  • 複製されていません
    並列読み取り

    Class.Model のピボットが に設定されている場所を決定します。

PVInstance から継承した プロパティ
  • 複製されていません
    スクリプト作成できません
    並列読み取り
  • 複製されていません
    スクリプト作成できません
    並列読み取り

方法

  • Activate():void

    Class.Tool の起動をシミュレートします。

  • Deactivate():void

    Class.Tool の無効化をシミュレートします。

Model から継承した 方法
  • AddPersistentPlayer(playerInstance : Player):void

    このモデルを特定のプレイヤーのために持続化するように設定します。 Model.ModelStreamingMode は、 PersistentPerPlayer に設定されなければ、動作が追加された結果により変更されることはありません。

  • モデルのすべてのパーツが含まれているボリュームの説明を返します。

  • Class.BasePart|BaseParts が含まれる最小限のバウンドボックスのサイズを返します。ModelModel.PrimaryPart が設定されている場合は、1>Class.BasePart|BaseParts1> が返されます。

  • このモデルオブジェクトが持続する Player すべてのオブジェクトを返します。このメソッドを Script から呼び出すか、LocalScript から呼び出すかによって動作は変わります。

  • モデルのキャノニカルスケールを返します。モデルの新規作成には、デフォルトで 1 が返されますが、Model/ScaleTo でスケールされると変更されます。

  • MoveTo(position : Vector3):void

    Class.Model.PrimaryPart|PrimaryPart を指定された位置に移動します。Class.Model.PrimaryPart が指定されていない場合は、モデルのルートパーツが使用されます。

  • RemovePersistentPlayer(playerInstance : Player):void

    このモデルは特定のプレイヤーのために再び持続しなくなります。 Model.ModelStreamingMode は、 PersistentPerPlayer に設定されて、結果として動作を変更するために変更された場合には持続しなくなります。

  • ScaleTo(newScaleFactor : number):void

    スケールファクターを設定し、すべての子孫インスタンスのサイズと場所を調整して、スケールファクターが 1 の場合、インスタンスのオリジナルサイズと場所に対するスケールファクターが相対的に変更されます。

  • TranslateBy(delta : Vector3):void

    Class.Model を Datatype.Vector3 のオフセットを保持しながら シフトすると、モデルのオリエンテーションを保持します。如果 他の Class.BasePart または Class.Terrain が新しい位置に既に存在する場合は、1> Class.Model は1>

PVInstance から継承した 方法
  • 並列書き込み

    Class.PVInstance のピボットを取得します。

  • PivotTo(targetCFrame : CFrame):void

    Class.PVInstance とそのすべての子孫 PVInstances は、ピボットが指定の CFrame に移動します。

イベント

プロパティ

CanBeDropped

並列読み取り

CanBeDropped プロパティは、プレイヤーが Tool をドロップできるかどうかを制御します。

[バックスペース] ボタンを押すと、ツールは Workspace に親化され、プレイヤーの Backpack から削除されます。如果 [バックスペース] ボタンを押さないと、ツールは装備されたままで残ります。

Enabled

並列読み取り

有効 プロパティは、Tool を使用できるかどうかに関連しています。これは、プレイヤーがツールを使用することを防ぐのに便利ですが、Backpack から削除する必要はありません。

common ツールを設定すると、プレイヤーはツールを使用できます。false ツールを設定すると、ツールは無効になり、プレイヤーはツールを使用できません;これはツールを

コードサンプル

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

並列読み取り

The Grip プロパティは、ツールの「グリップ」プロパティを 1つの CFrame に保存します。これらのプロパティは、プレイヤーがツールを持ってい

コードサンプル

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

非表示
複製されていません
並列読み取り

ツールの方向をキャラクターの手の中で指定するプロパティの 1 つ。これは、R02R12、およびR22のグリップの回転マトリックスの値を表します。

ツールを持つ方法を制御する他のツールプロパティには、Tool.GripUpTool.GripRight、およびTool.GripPosが含まれます。これらのプロパティは、2>Class.Tool.Grip2> プロパティの単一の

コードサンプル

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

非表示
複製されていません
並列読み取り

このプロパティは、ツールの穿刺マトリックスの位置オフセットを制御します。ツールのキャラクターがツールをどのように配置するかを設定するのに使用されるいくつかのプロパティの 1つです。

ツールを持つ方法を制御する他のプロパティには、 Tool.GripUpTool.GripRight 、および Tool.GripForward が含まれます。すべてのこれらのプロパティは、 2>Class.Tool.Grip2> プロパティの単一の

コードサンプル

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

非表示
複製されていません
並列読み取り

ツールの方向をキャラクターの手の中で指定するプロパティの 1 つ。これは、R00R10、およびR20のグリップの回転マトリックスの値を表します。

ツールを持つ方法を制御する他のツールプロパティには、Tool.GripUpTool.GripForward、およびTool.GripPosが含まれます。これらのプロパティは、2>Class.Tool.Grip2> プロパティの単一の

コードサンプル

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

非表示
複製されていません
並列読み取り

ツールの方向をキャラクターの手の中で指定するプロパティの 1 つ。これは、R01R11、およびR21のグリップの回転マトリックスの値を表します。

ツールを持つ方法を制御する他のツールプロパティには、Tool.GripRightTool.GripForward、およびTool.GripPosが含まれます。これらのプロパティは、1> Datatype.CFrame1> 内の単一の <

コードサンプル

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

並列読み取り

The ManualActivationOnly プロパティは、Tool をスクリプトを実行しなくても有効にするかどうかを制御します。

[ツール] を [ツール] に設定すると、ツールは Tool.Activated が呼び出されたときにのみ Tool:Activate() を発行します。これにより、 ContextActionService:BindActivate() 機能もサプレスされます。

フラグを「偽」に設定すると、マウスクリック (ツールが装備されているとき) も 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

並列読み取り

ツールヒントプロパティは、プレイヤーの MouseTool の上にホバーすると表示されるメッセージを制御します。

一般的に、このプロパティの値は、ツールが何であるか、またはその使用方法を説明する必要があります。たとえば、シャベルツールの場合、ツールヒントを設定して:


tool.ToolTip = "Shovel"

または


tool.ToolTip = "Use to dig"

または


tool.ToolTip = "Shovel - Use to dig"

方法

Activate

void

この関数は、Tool の起動をシミュレートします。ツールはこの機能を使用するために装備している必要があります。


戻り値

void

コードサンプル

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

void

この関数は、Tool の無効化をシミュレートします。ツールはこの機能を使用するために装備している必要があります。


戻り値

void

コードサンプル

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 tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.Parent = game.Players.LocalPlayer.Backpack
function onActivation()
print("Tool activated")
end
tool.Activated:Connect(onActivation)

Deactivated

このイベントは、Tool が装備されている状態でプレイヤーがクリックをリリースすると発動します。通常、プレイヤーがツールを使用していないときにアクションを実行するために使用されます。

次のコード、LocalScript に配置されると、ローカルプレイヤーの Backpack にツールが作成され、ツールが装備されている状態で、プレイヤーがクリックをリリースすると、「ツールが無効になっています」と表示されます。


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

Equipped

このイベントは、プレイヤーが Tool を装備したときに発生します (Backpack から取り外します)。

このイベントの反対、 Tool.Unequipped 、は、プレイヤーがツールをバックパックに入れるときにツールを装備解除するかどうかを判断するために使用できます。

注: このイベントは、Class.Tool.RequiresHandle が有効になっているときには 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 を使用して、プレイヤーがバックパックからツールを装備する時間を判断できます。

注: このイベントは、Class.Tool.RequiresHandle が有効になっているときには Tool.RequiresHandle