Intro to Player Tools – Weapons, Wands, etc.
Intro to Player Tools – Weapons, Wands, etc.
Tools are a special instance used to implement weapons, wands, and other interactive tools. In this tutorial, you’ll learn how to create tools, where to put them in the game hierarchy, and how to write a basic tool script.
Creating a Tool
All tools begin as an empty container which holds all of the instances that make up the tool, including parts, sound effects, and the scripts which provide functionality.
Creating the Tool Container
To create a new tool container:
In the Explorer window, hover over Workspace and click the button.
Under the Interaction section, select Tool.
Inserting Parts or Meshes
Any parts or meshes added to the tool will be the model that players see. You can create swords, rocket launchers, magic wands, or almost any tool you’d like!
Just like other models, tools can be made out of multiple parts. Since players will carry tools around (or swing them wildly like a sword!), the tool’s parts should be welded together using
Confirm All Parts Are Non-AnchoredWhen constructing tools, make sure tool parts are not anchored. If any part of the tool is anchored, players will get stuck in place when equipping it.
Tools Without PartsIt's possible to make a tool without parts or meshes! In this case, the tool simply becomes an inventory item that waits for player input, like a magic spell that can be cast by clicking another character or touching the screen. To make a tool that does not use a mesh or parts, look in the tool properties and un-check RequiresHandle.
Setting the Tool Handle
Tools that players carry must contain a single part named Handle. The handle is where the tool will attach to the player’s hand.
For example the magic wand below is actually split into three parts: the glowing tip, the main body, and the red handle. When a player equips the wand, they’ll hold it at whichever part is named Handle.
- Only one part should be named Handle. If you have multiple parts called Handle, the tool will randomly pick one of them as the hand attachment point.
- The Handle part must be a direct child of the tool container — it cannot be nested inside a model or folder within the container.
Changing the Tool Grip
If your tool is dragging on the ground or facing backwards, you can fix it by changing the tool’s grip properties.
Every tool is different, so you’ll need to experiment with changing the values next to the GripForward, GripRight, and GripUp properties until the tool looks correct.
Tools can also be offset from the character’s hand with the GripPos property. This can be useful when making a tool that should appear to rest on the player’s shoulder.
Customizing the Tool Icon
Tools that a player owns are stored in their
Backpack. On screen, this is represented by an action bar which shows each tool in the backpack.
Use the following properties to customize the tool’s appearance in the action bar:
- TextureID — The tool icon. Set the image ID for this property the same way as decals, image buttons, etc.
- ToolTip — The on-hover tooltip name.
Can/Can’t be Dropped
By default, a player can drop a tool by pressing the Backspace key (delete on macOS). You can disable this option by setting the CanBeDropped property of the tool to
false. If CanBeDropped is
false, pressing Backspace or delete will return the tool to the player’s backpack.
Adding Tools to a Game
Once your tool is set up, it should be placed in the proper area of your game’s object hierarchy.
Default Starting Tool
If you want all players to start out with a tool in their inventory, put it inside the StarterPack folder. When any player spawns, the tool will get copied to their backpack.
A tool can be placed in the workspace if players will be able to collect it as they explore. For example, you might place a super rocket launcher in a hard-to-reach area of your game world.
Some tools should be awarded when a player does something special, or offered for sale in an in-game store. These should be put inside ServerStorage and then cloned to the player’s backpack at the proper time.
Bringing Tools to Life
To make tools do interesting things in the game world, you’ll need to add scripts.
There are four tool-specific conditions you can work with in a tool scrip. These indicate the state of the tool and the player’s input with it.
||Occurs when the player selects the tool from their backpack.|
||Occurs when the player drops the tool or switches tools.|
||Occurs when the player starts activating the tool (clicks, taps, or presses A on a gamepad).|
||Occurs when the player stops the activation input (releases the button or touch).|
Although you might not need all four conditions when designing a tool, this code can be used as a basic tool script template:
local tool = script.Parent local function onEquip() end local function onUnequip() end local function onActivate() end local function onDeactivate() end tool.Equipped:Connect(onEquip) tool.Unequipped:Connect(onUnequip) tool.Activated:Connect(onActivate) tool.Deactivated:Connect(onDeactivate)
tool) to point to the core tool container.
Adding a Basic Script
Here’s how to add a simple server script (
Script) to a tool. When equipped, the player will be able to click the screen to change night to day and vice-versa.
- In the Explorer window, hover over the tool container, click the and insert a Script.
- Copy the following code and paste it into your script.
local tool = script.Parent local function onActivate() if game.Lighting.ClockTime >= 8 and game.Lighting.ClockTime < 16 then game.Lighting.ClockTime = 20 else game.Lighting.ClockTime = 8 end end tool.Activated:Connect(onActivate)
- Playtest your game, pick up the tool, and then click anywhere in the game world. The time of day should change from night to day and vice-versa with each click!
Script vs. LocalScript
The above example uses just a server script (
Script), but most tools will require both a server script and a local script (
LocalScript) where each takes care of certain aspects of the tool’s behavior.
Remember these core differences between each script type:
- Script — Manages changes within the overall game world, visible to all players, like unlocking a door, shooting an arrow, etc.
- LocalScript — Manages things that happen only on the player’s computer/device, like detecting exactly where the screen is touched or clicked.
Here are some example tools and the aspects which would be managed by either a local script or a server script:
|Tool||Local Script||Server Script|
|Creator's Wand||Detects where the player touches or clicks on the screen.||Creates a new part at the location within the game world where the player touched or clicked.|
|Invisibility Cloak||—||Temporarily makes the player invisible to all other players, while the cloak is equipped.|
|Mega-Bow||Detects how long the player activates the tool (time between activation and deactivation).||Shoots a magical arrow with greater or lesser power, depending on the detected activation time.|
Troubleshooting a ToolA tool might work perfectly in Studio, but not in a live Roblox game. If this occurs, remember these tips:
- Local scripts and server scripts are separated by a “wall” so they can't directly listen to each other. Because of this, you'll need to send a
RemoteEventover the wall to send messages between the two scripts.
- Make sure that each script (
LocalScript) is taking care of exactly what it's supposed to! Review the notes and examples above for clarification.
You should now be familiar with designing tools, adding them to your game, and writing scripts to give them awesome powers!