Lesson 6 of 12
The wrench: tools, raycasts, tags
Make a melee weapon for Roblox that cannot be cheated. Build Beacon Yard's wrench Tool, send a swing request, validate it on the server and hit the drone with a raycast filtered by a CollectionService tag.
By the end you can
- Build a Tool with a Handle and give it to every player through StarterPack
- Validate a swing request on the server and decide the hit with a filtered raycast
- Use CollectionService tags so the ray can only see the drone
Before this: The drone: movement, targeting, damage, Security: never trust the client
1Three hits and the drone is scrap
Equip the wrench with 1, face the drone and click. Its health bar drops by a third, it flashes white and freezes. Two more hits and it breaks apart. Swing at the floor and nothing happens except the sound.
Three accepted hits. Each one deals 34 and stuns the drone.
Transcript
- 0:03 Each accepted hit deals 34.
- 0:04 Health goes from 100 to 66, then to 32.
- 0:05 The third hit destroys the drone. The swings are spaced past the 0.4 second gap.
DRONE_MAX_HEALTH is 100 and WRENCH_DAMAGE is 34. How many hits destroy a fresh drone?
Answer
3 hits. 100, 66, 32, then -2. The third hit takes it below zero. The suite's wrench_kill test swings exactly three times.
Open this step in lesson mode · Link to this step · This confused me
2A Tool needs a Handle
A Tool is an object a player carries and equips. Roblox shows it in the backpack hotbar, and when equipped it moves from the player's Backpack into their character. A tool that is held in the hand needs a part named exactly Handle as a direct child1.
local tool = Instance.new("Tool")
tool.Name = "Wrench"
tool.CanBeDropped = false
tool.RequiresHandle = true
local template = AssetModels.template("Wrench")
local uploaded = if template ~= nil then template:Clone() else nil
local meshHandle = if uploaded ~= nil then uploaded:FindFirstChild("Handle", true) else nil
if uploaded ~= nil and meshHandle ~= nil and meshHandle:IsA("BasePart") then
meshHandle.CanCollide = false
meshHandle.CanTouch = false
meshHandle.CanQuery = false
meshHandle.Massless = true
meshHandle.Parent = tool
uploaded:Destroy()
else
if uploaded ~= nil then
uploaded:Destroy()
end
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1, 1, 3)
handle.Color = Color3.fromRGB(192, 144, 64)
handle.Material = Enum.Material.Metal
handle.CanCollide = false
handle.Massless = true
handle.Parent = tool
end
tool.Parent = StarterPack
StarterPack copies its tools into each player's Backpack when they spawn. createWrench also gives the tool to players who are already in the server, which is why it runs before the map is built: a character that spawns before the wrench exists would arrive empty-handed.

Select a numbered pin, or a row below, to read what it marks.
The wrench in hand. Select the pins for the Handle and the hotbar slot.
The handle part is named Grip instead of Handle. RequiresHandle is true. What happens when a player equips the wrench?
Answer
The character holds nothing, because the tool has no Handle to weld to the hand. The engine looks for a child named Handle. Without one, a RequiresHandle tool has nothing to attach to the hand.
Open this step in lesson mode · Link to this step · This confused me
3A swing is a request, not a hit
The client decides where you aimed. It fires the Swing remote with two vectors, an origin near your head and a unit direction, and nothing else. It never sends damage and never decides whether it hit.
local function fireSwing()
local character = player.Character
local camera = workspace.CurrentCamera
if character == nil or camera == nil then
return
end
local origin, direction = aim(character, camera)
if origin == nil or direction == nil then
return
end
playSwing(character)
swing:FireServer(origin, direction)
The server's trySwing treats both vectors as untrusted. It checks their types, rejects infinite or zero-length vectors, requires the wrench to be in the character, and rejects an origin more than 8 studs from the head. It also enforces a 0.4-second gap between swings.
if (origin - head.Position).Magnitude > ORIGIN_MAX_STUDS then
return "rejected"
end
local now = workspace:GetServerTimeNow()
local previousSwing = lastSwing[player]
if previousSwing ~= nil and now - previousSwing < SWING_GAP then
return "rejected"
end
lastSwing[player] = now
local SWING_GAP = 0.4
local lastSwing = nil
local accepted = 0
for _, now in { 0, 0.2, 0.5, 0.6, 1.0 } do
if lastSwing == nil or now - lastSwing >= SWING_GAP then
lastSwing = now
accepted += 1
end
end
print("accepted", accepted)
accepted 3Which values does the client send with Swing:FireServer?
Answer
An origin (Vector3); A unit direction (Vector3). Only origin and direction. The engine adds the Player as the first argument of OnServerEvent, and the server works out the hit and the damage.
Open this step in lesson mode · Link to this step · This confused me
4The server fires a laser
Once the request passes, the server decides the hit with a RaycastRaycastA test that traces a straight line through the world and reports the first part it meets.Think of it as a laser pointer.. workspace:Raycast(origin, direction, params) traces a line from origin along direction and returns the first part it meets, or nil2. The direction is the whole line, so its length is the range: the server multiplies the unit direction by WRENCH_RANGE, 14 studs.
| In the picture | In Roblox |
|---|---|
| Where you hold the pointer | The origin |
| Where you point it, and how far it reaches | The direction vector and its length |
| The red dot | The RaycastResult: the part, position and normal of the hit |
A raycast is a laser pointer. Point it from a spot in a direction, and it tells you the first thing the dot lands on.
Think of it as A laser pointer
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = CollectionService:GetTagged(DRONE_TAG)
local result = workspace:Raycast(origin, direction.Unit * Config.WRENCH_RANGE, params)
if result == nil or not isTaggedDrone(result.Instance) then
return "miss"
end
DroneService.damageFromWrench(Config.WRENCH_DAMAGE)
feedback(player, "hit", nil)
return "hit"
After a refactor the wrench never hits a drone more than a stud away. Which line is wrong?
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = CollectionService:GetTagged(DRONE_TAG)
local result = workspace:Raycast(origin, direction.Unit, params)
if result == nil or not isTaggedDrone(result.Instance) then return "miss" end
Answer
Line 4: local result = workspace:Raycast(origin, direction.Unit, params). Fixed: local result = workspace:Raycast(origin, direction.Unit * Config.WRENCH_RANGE, params). Raycast's second argument is the full segment. A unit vector is 1 stud long, so the ray stops after 1 stud. Multiply by WRENCH_RANGE to reach 14 studs.
Open this step in lesson mode · Link to this step · This confused me
5Tags: a coloured sticker on the drone
The ray's filter is an Include list built from CollectionService:GetTagged("Drone"). DroneService adds the Drone Tag (CollectionService)Tag (CollectionService)A string label on an instance that scripts can search for.Think of it as a coloured sticker. to the drone's root when it spawns. Tags replicate from the server to clients, and any script can ask for every instance with a tag3.
A tag is a coloured sticker. Stick a red dot on every drone and you can ask the room for "everything with a red dot" without knowing where each one is.
Think of it as Coloured stickers
Both sidesRemember: CollectionService tags is coloured stickers.
With FilterType = Include, the ray considers only the drone's parts. The floor, walls and players are invisible to it. That is why swinging at the ground is always a miss.
A swing at the ground: accepted, so the sound plays, but the ray finds nothing tagged Drone.
Transcript
- 0:00 The server accepted the swing, so the swing sound can play.
- 0:01 The include list is only the Drone tag. The ground is not a hit.
- 0:04 The bar stays where it was.
The drone is 10 studs away, behind the 2-stud wall. You swing straight at it. What does the server decide?
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = CollectionService:GetTagged("Drone")
local result = workspace:Raycast(origin, direction.Unit * 14, params)
Answer
A hit: the wall is not in the Include list, so the ray passes through it. Include filters make every other part invisible to the ray, walls included. Beacon Yard accepts that because the yard is open. A game with cover would add the walls to the list and check that the first hit is the drone.
Open this step in lesson mode · Link to this step · This confused me
6Hit confirm: telling a hit from a miss
Because the server decides the hit, the player needs a clear hit confirm so a miss and a hit never feel alike. Look at the two feedback(...) calls inside CombatService.trySwing:
feedback(player, "swing", nil)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = CollectionService:GetTagged(DRONE_TAG)
local result = workspace:Raycast(origin, direction.Unit * Config.WRENCH_RANGE, params)
if result == nil or not isTaggedDrone(result.Instance) then
return "miss"
end
DroneService.damageFromWrench(Config.WRENCH_DAMAGE)
feedback(player, "hit", nil)
return "hit"
Every accepted swing fires Feedback with "swing", even when the ray misses. Only a confirmed hit on a tagged drone fires "hit". At m06-drone-wrench, SoundClient plays Config.SOUNDS.swing on "swing" and Config.SOUNDS.hit on "hit", while passing nil as the second argument leaves the HUD silent. Passing a short confirm string (such as "-34") triggers the HUD toast on every hit too, so even a muted player sees the confirmation. From m07-feel onward VfxClient also listens to "hit" for a burst of sparks, and Module 14's Game feel: juice, hit stop and feedback adds hit stop, reduced-motion-aware camera shake, damage numbers and layered audio on top of this same server confirm.
local feedback = Signal.new()
feedback:Connect(function(kind, text)
if kind == "swing" then
print("audio: swing swoosh")
elseif kind == "hit" then
print("audio: hit clang | hud:", text or "(silent)")
end
end)
local function trySwing(hitDrone)
feedback:Fire("swing", nil)
if not hitDrone then
return "miss"
end
feedback:Fire("hit", "-34")
return "hit"
end
print("swing 1 ->", trySwing(false))
print("swing 2 ->", trySwing(true))
audio: swing swoosh
swing 1 -> miss
audio: swing swoosh
audio: hit clang | hud: -34
swing 2 -> hitWhy does CombatService fire Feedback with "hit" only after the server raycast succeeds, instead of letting CombatClient play the hit confirm immediately on click?
Answer
Only the server knows whether the swing passed validation and hit the drone, so a client-side confirm would lie on misses and rejected swings. Swing cues can feel instant on click, while hit confirmation must wait for the server's raycast verdict so a miss or a rejected swing never reports a fake hit.
Open this step in lesson mode · Link to this step · This confused me
7Where the laser picture breaks
A laser pointer lights up the first thing in its path, whatever it is. A raycast does too, but only among the things its filter lets it see. Answer first, then open the breakdown.
Both sidesRemember: A raycast is a laser pointer.
Where does it break?“A laser pointer” is a good picture of a raycast. Where does it stop being true?
It breaks here. It reports only the first hit, and filters make whole groups of parts invisible to it, so it can pass through walls or stop on the wrong thing.
The true model. Raycast tests one segment against the parts its RaycastParams allow and returns the nearest intersection or nil. Include lists see only listed parts; Exclude lists see everything else. To respect cover, the ray must be able to see the cover.
You change the filter to Exclude the player's own character, so the ray sees everything else. The drone is behind a crate. What does Raycast return?
Answer
The crate, the first part on the line; the drone is never reported. Raycast returns only the first hit. With an Exclude filter the crate is first, and isTaggedDrone(crate) is false, so the swing is a miss. Cover works; hitting through walls does not.
Open this step in lesson mode · Link to this step · This confused me
8Build it: add the wrench
Other ways pros do this
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| Raycast | One thin line from the player along the aim. | Precise melee and hitscan weapons. What Beacon Yard uses. | A thin line can slip past a small target; the aim has to be good. |
| Shapecast | Blockcast or Spherecast sweeps a shape along the line. | Forgiving melee swings and thick projectiles. | Slightly more costly, and the shape size needs tuning. |
| Hitbox query | GetPartBoundsInBox or GetPartsInPart around the weapon at the moment of the swing. | Wide swings that should hit anything in an arc. | Easy to make too generous; still must run on the server. |
| Touched on the weapon | The blade's Touched event during an animation. | Quick prototypes. | Fires on the client's simulated character, misses fast swings and is easy to exploit. Studios avoid it for damage. |
Build along
src/server/CombatService.luausrc/client/CombatClient.luausrc/server/Remotes.luausrc/server/init.server.luau
In the game repo, run
git diff m05-the-round m06-drone-wrench -- src/server/Remotes.luauandgit diff --stat m05-the-round m06-drone-wrench -- src/server/CombatService.luau src/client/CombatClient.luau.You should see CombatService.luau and CombatClient.luau are new, and Remotes.luau's REMOTE_NAMES gains ShopOpen, ShopBuy and Swing.
Check out
m06-drone-wrenchand opensrc/server/init.server.luau.You should see init.server.luau calls CombatService.start() before MapBuilder.build(), with a comment explaining why.
Run
rojo serve, connect Studio and press Play.You should see StarterPack holds a Tool named Wrench during Play, and the hotbar shows Wrench in slot 1.
Start a drill, press 1 to equip the wrench and click while facing the drone.
You should see Three hits destroy the drone. A swing at the floor plays the sound but does not change the health bar.
Open this step in lesson mode · Link to this step · This confused me
9Challenges
Level 1, Apprentice
Challenge
Shorten the wrench to 4 studs and find the new sweet spot, then restore it.
- Start from
- The game at milestone m06 (download)
Done means
- With WRENCH_RANGE at 4 you have to stand close to land a hit
- WRENCH_RANGE is 14 again afterwards
Hints
- WRENCH_RANGE is in Config.luau.
- The client uses it too, to aim; both sides read the same Config.
An exploiter fires Swing with an origin right next to the drone, 30 studs from their head. What does trySwing return?
Answer
"rejected". The origin must be within 8 studs of the head. A 30-stud origin is rejected before any ray is cast, so the exploit cannot reach across the yard.
Level 2, Builder
Challenge
Make walls block the wrench.
- Start from
- The game at milestone m06 (download)
Done means
- A swing at the drone through a wall is a miss
- A clear swing still hits, and wrench_kill still passes
Hints
- Switch the filter to Exclude and put the swinging character in the list.
- isTaggedDrone already checks that the first hit belongs to the drone.
Level 3, Professional
Challenge
Add a charged swing whose strength the server times.
- Start from
- The game at milestone m06 (download)
- Grade it
- To grade work from an earlier milestone, apply your challenge changes to a checkout based on
m14-ship, which includes the Course Runner. In Studio, press Play, then rungame.ServerScriptService.RunGameTests:Invoke("wrench", "wrench-charge")in the server command bar. Copy the pass code from Output.
Done means
- CombatService exposes beginCharge(player) to record when that player started holding a charge on the server
- CombatService.trySwing(player, origin, direction, charge?) accepts an optional 4th charge argument in seconds, capped at 1.2s
- trySwing returns "rejected" and deals 0 damage if charge > 1.2 or if the player has not held the charge long enough on the server
- A swing with charge = nil deals Config.WRENCH_DAMAGE (34), even right after a rejected charge, so the plain tap and the existing wrench_kill test still work
- A full 1.2s earned charge deals Config.WRENCH_DAMAGE + 16, and a charge below a small minimum (the reference solution uses 0.45s) is rejected
- The swing gap still applies between swings: the test waits 0.5s between the tap and the full-charge swing
- challenges/wrench.luau prints TEST PASS for charge_reject_high, charge_reject_unearned, charge_tap and charge_full
Hints
- Store the charge start time per player inside CombatService when beginCharge(player) is called, and measure elapsed time on the server.
- Allow a small timing grace window on the server check (the test waits 1.15s before requesting 1.2s, and 0.12s before requesting 1s).
- Scale bonus damage linearly from the base at the minimum charge up to +16 at 1.2s, and keep charge = nil equal to WRENCH_DAMAGE so existing tests pass.
- Read challenges/solutions/wrench.md only after you try.
Open this step in lesson mode · Link to this step · This confused me
10Recap
Retiring the analogy
You no longer need “a laser pointer”. Raycast tests one segment against the parts its RaycastParams allow and returns the nearest intersection or nil. Include lists see only listed parts; Exclude lists see everything else. To respect cover, the ray must be able to see the cover.
Recap
- The wrench is a Tool with a part named Handle, given to every player through StarterPack before the first spawn.
- The client sends only an origin and a direction; the server checks the tool, the 8-stud origin, the 0.4-second gap, and casts a 14-stud ray.
- The ray's Include filter is the set of parts tagged Drone, so it sees only the drone and returns the first hit among them.
A raycast is a laser pointer, until it reports only the first hit, and filters make whole groups of parts invisible to it, so it can pass through walls or stop on the wrong thing.
CollectionService tags is coloured stickers, until a sticker does nothing until code looks for it, and a tag on the drone's root does not tag its children.
Queued for review
Next First publish: private cloud place, API access and Ids.local
Open this step in lesson mode · Link to this step · This confused me