도구는 Humanoid 개체가 장착할 수 있는 개체입니다.플레이어의 경우, 그들은 Backpack 개체에 부모로 지정된 Player 개체에 저장됩니다.게임 내에서 플레이어는 화면 하단에 아이콘으로 나타나는 여러 도구를 가질 수 있습니다.도구를 장착하면 백팩에서 이동하여 모델로 이동합니다.기본적으로 도구는 오른손에 보관되고 내부에 핸들이 있으며, 이 핸들은 "핸들"이라는 이름으로 명명되어 있습니다(비록 한 가지가 필요하지 않은 경우 내부에 "핸들"이라는 이름이 끄기).재생성되는 플레이어에게 제공될 도구는 StarterPack에 저장되어야 합니다.
데스크톱에서 숫자 키(1, 2, 3...)를 누르면 도구가 장착됩니다.장착된 도구는 백스페이스를 눌러 작업 영역에 떨어뜨릴 수 있습니다.도구를 떨어뜨리고, 죽고, 다시 생성하여 도구를 복제할 수 없도록 Tool.CanBeDropped 끄는 것이 좋습니다.게임패드에서 LB와 RB 버튼은 도구를 장착합니다.활성화를 왼쪽 클릭(또는 게임패드의 오른쪽 트리거)으로 비활성화할 수 있습니다. 설정 Tool.ManualActivationOnly 을 사용하여.이렇게 하려면 다른 사용자 입력을 통해 자신을 활성화하도록 해야 합니다.
도구가 사용자 입력을 캡처하는 유일한 방법은 아닙니다.또한 ContextActionService , UserInputService 또는 Player:GetMouse() 을 사용할 수 있습니다.도구에 여러 작업을 수행할 수 있는 도구가 필요한 경우, 도구가 장착되어 있는 동안 키를 누르는 등의 작업을 수행하려면 컨텍스트 액션 서비스의 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.
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!
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 함수가 있는지 여부를 결정합니다.
플레이어의 마우스가 백팩에 있는 도구에 호버할 때 표시되는 메시지를 제어합니다.
플레이어의 백팩에 표시되는 도구에 대한 텍스처 아이콘.
인스턴스 스트리밍이 활성화된 경험에 대한 모델의 세부 수준을 설정합니다.
인스턴스 스트리밍이 활성화된 경우 Models에서 모델 스트리밍 행동을 제어합니다.
기본 부분의 Model 또는 nil 명시적으로 설정되지 않은 경우.
편집기에만 사용되는 속성으로, 피벗 주위에 모델을 확장하는 데 사용됩니다. 이 속성을 설정하면 피벗에서 Model/ScaleTo가 호출된 것처럼 규모가 이동됩니다.
어떤 Model 가 가지고 있지 않은 피벗의 위치를 결정합니다. where the pivot of a which does not have a set Model.PrimaryPart 는.
메서드
메서드가 Model에서 상속되었습니다지정된 플레이어에 대해 이 모델을 영구적으로 유지하도록 설정합니다.Model.ModelStreamingMode 는 추가로 인해 변경된 동작을 위해 PersistentPerPlayer 로 설정해야 합니다.
모델의 모든 부분을 포함하는 볼륨의 설명을 반환합니다.
설정되면 의 모든 것을 포함하는 가장 작은 바인딩 상자의 크기를 반환합니다.Returns the size of the smallest bounding box that contains all of the in the , aligned with the if it is set.
이 모델 개체가 영구적으로 유지하는 모든 Player 개체를 반환합니다.이 메서드가 Script 또는 LocalScript 호출되는지에 따라 동작이 달라집니다.
새로 생성된 모델에 기본값이 1인 모델의 캐논 규모를 반환하며, Model/ScaleTo를 통해 크기가 조정될 때 변경됩니다.
PrimaryPart를 지정된 위치로 이동합니다. 기본 부품이 지정되지 않았으면 모델의 루트 부품이 사용됩니다.
지정된 플레이어에 대해 이 모델을 더 이상 영구적으로 유지하지 않습니다.Model.ModelStreamingMode 는 제거로 인해 변경된 동작을 위해 PersistentPerPlayer 로 설정해야 합니다.
모델의 규모 요소를 설정하여 모든 하위 인스턴스의 크기와 위치를 조정하여 규모 요소가 1일 때 초기 크기와 위치와 관련하여 그 규모 요소가 있도록 합니다.
모델의 방향을 유지하면서 주어진 오프셋 Model에 의해 이동하여 Vector3로 전환합니다.새 위치에 이미 다른 BasePart 또는 Terrain 가 있으면 해당 Model 가 해당 개체를 겹치게 합니다.
PVInstance의 피벗을 가져옵니다.
피벗이 지금 지정된 PVInstance 에 위치하도록 모든 하위 요소 PVInstances 와 함께 변환하여 피벗이 지금 지정된 CFrame 에 위치합니다.
이벤트
도구가 장착되어 있는 동안 플레이어가 클릭하면 발생합니다.
도구가 장착되고 활성화되어 있는 동안 플레이어가 클릭을 릴리스하면 발생합니다.
도구가 장착되면 발생합니다.
도구가 장착되지 않은 경우 발생합니다.
속성
CanBeDropped
CanBeDropped 속성은 플레이어가 Tool를 드롭할 수 있는지 여부를 제어합니다.
true이면 백스페이스 버튼이 누르면 도구가 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.
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
속성은 도구의 "그립" 속성을 단일 으로 저장합니다.이러한 속성은 플레이어가 도구를 어떻게 들고 있는지 위치하고 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.
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 값을 나타냅니다.This represents the , , and values of the grip CFrame rotation matrix.
캐릭터가 도구를 잡는 방법을 제어하는 다른 도구 속성에는 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.
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.
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 값을 나타냅니다.This represents the , , and values of the grip CFrame rotation matrix.
캐릭터가 도구를 잡는 방법을 제어하는 다른 도구 속성에는 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.
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 값을 나타냅니다.This represents the , , and values of the grip CFrame rotation matrix.
캐릭터가 도구를 잡는 방법을 제어하는 다른 도구 속성에는 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.
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
ManualActivationOnly 속성은 스크립트에서 명시적으로 Tool 를 실행하지 않고도 Tool:Activate() 가 활성화될 수 있는지 여부를 제어합니다.
참으로 설정되면 도구는 만 발사되고 가 호출될 때만 함수가 억제됩니다. 이것은 또한 함수를 억제합니다.
거짓으로 설정되면 도구가 장착되어 있을 때 마우스 클릭도 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.
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
도구 설명 속성은 플레이어의 위에 있는 에 마우스를 올렸을 때 표시될 메시지를 제어합니다.
일반적으로 이 속성의 값은 도구의 기능이나 사용 방법을 설명해야 합니다.예를 인스턴스, 삽 도구의 경우 도구 팁을 다음으로 설정할 수 있습니다.
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.
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.
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 , 플레이어가 배낭에 도구를 넣어 언제 도구를 장비 해제할지 결정하는 데 사용할 수 있습니다.
이 이벤트는 활성화되지 않고 핸들이 없을 때 발생하지 않습니다.Note that this event does not fire when Tool.RequiresHandle is enabled and no handle is present.
매개 변수
플레이어의 마우스.
코드 샘플
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.
local Tool = script.Parent
local function onEquipped(_mouse)
print("The tool was equipped")
end
Tool.Equipped:Connect(onEquipped)
Unequipped
이 이벤트는 플레이어가 Tool(그것을 그들의 Backpack에 넣음)를 장비 해제할 때 발생합니다.
이 이벤트의 반대, Tool.Equipped , 플레이어가 배낭에서 도구를 꺼내 장착할 때를 결정하는 데 사용할 수 있습니다.
이 이벤트는 활성화되지 않고 핸들이 없을 때 발생하지 않습니다.Note that this event does not fire when Tool.RequiresHandle is enabled and no handle is present.