How do I make a combat system in Roblox Studio?
Updated · by the Superbullet team
A Roblox combat system has two halves. The player's computer (the client) reads the click and plays the swing animation, then tells the server "I swung" through a RemoteEvent. The server checks the cooldown, finds who was hit and deals the damage, so exploiters can't fake hits. You can write this yourself in about 150 lines of Luau (full code below), or install a ready-made combat system with SuperbulletAI and change it from there.
Written by the SuperbulletAI team. The by-hand route below works with no paid tools.
Pick your route
| Write it yourself | Install or generate it with SuperbulletAI | |
|---|---|---|
| Cost | Free (Roblox Studio is free) | Free plan: 1M tokens/month, 150K/day. Pro: $20/month. Pricing |
| Time to a working punch combo | An afternoon if you know some Luau | Minutes, plus uploading the animations |
| What you learn | How Roblox networking works | How a full system is laid out (you can read all the code) |
| Best for | Learning, or very custom combat | Getting combos, blocking, VFX and sounds working fast, then tuning |
How a good combat system is laid out
- Client (LocalScript): reads input, plays the animation right away so it feels instant, and fires a RemoteEvent. It sends no damage, no target and no position. The client can lie, so it only says "I pressed attack".
- Server (Script): owns everything that matters: the cooldown, the combo step, the hitbox, block checks and damage.
- Shared state: things like
BlockingorStunnedare Attributes on the character, set only by the server, so every script can read them.
The by-hand route
1. Set up the objects
In the Explorer:
ReplicatedStorage→ add a Folder namedRemotes→ inside it add two RemoteEvents:AttackandBlock.ServerScriptService→ add a Script namedCombatServer.StarterPlayer→StarterPlayerScripts→ add a LocalScript namedCombatClient.- Make your swing animations in the Animation Editor (one per combo hit, for example 4), publish them, and copy their IDs.
2. The server script
Put this in CombatServer. Every rule lives here.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage:WaitForChild("Remotes")
local attackRemote = remotes:WaitForChild("Attack")
local blockRemote = remotes:WaitForChild("Block")
local COOLDOWN = 0.4 -- server cooldown, a bit lower than the client's so lag doesn't eat real swings
local COMBO_RESET = 1.2 -- seconds without a swing before the combo starts again
local DAMAGE = { 8, 8, 10, 14 } -- damage for combo hits 1, 2, 3 and 4
local BLOCK_MULTIPLIER = 0.2 -- blocking takes 20% damage
local HITBOX_SIZE = Vector3.new(5, 5, 5)
local HITBOX_OFFSET = CFrame.new(0, 0, -3.5) -- 3.5 studs in front of the attacker
local state = {} -- [player] = { lastSwing = number, combo = number }
local function getState(player)
local s = state[player]
if not s then
s = { lastSwing = 0, combo = 0 }
state[player] = s
end
return s
end
attackRemote.OnServerEvent:Connect(function(player)
local s = getState(player)
local now = os.clock()
if now - s.lastSwing < COOLDOWN then
return -- swinging too fast: ignore it
end
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
local root = character and character:FindFirstChild("HumanoidRootPart")
if not (humanoid and root) or humanoid.Health <= 0 then
return
end
if character:GetAttribute("Blocking") or character:GetAttribute("Stunned") then
return -- can't attack while blocking or stunned
end
-- the server decides which combo hit this is
if now - s.lastSwing > COMBO_RESET then
s.combo = 1
else
s.combo = (s.combo % #DAMAGE) + 1
end
s.lastSwing = now
-- hitbox: a box in front of the attacker, ignoring the attacker
local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = { character }
local parts = workspace:GetPartBoundsInBox(root.CFrame * HITBOX_OFFSET, HITBOX_SIZE, params)
local alreadyHit = {}
for _, part in parts do
local targetModel = part:FindFirstAncestorOfClass("Model")
local targetHumanoid = targetModel and targetModel:FindFirstChildOfClass("Humanoid")
if targetHumanoid and targetHumanoid.Health > 0 and not alreadyHit[targetHumanoid] then
alreadyHit[targetHumanoid] = true -- each target is hit once per swing
local damage = DAMAGE[s.combo]
if targetModel:GetAttribute("Blocking") then
damage = math.floor(damage * BLOCK_MULTIPLIER)
end
targetHumanoid:TakeDamage(damage)
end
end
end)
blockRemote.OnServerEvent:Connect(function(player, isBlocking)
if typeof(isBlocking) ~= "boolean" then
return -- the client sent something odd: ignore it
end
local character = player.Character
if character then
character:SetAttribute("Blocking", isBlocking)
end
end)
Players.PlayerRemoving:Connect(function(player)
state[player] = nil
end)
3. The client script
Put this in CombatClient. Replace the animation IDs with yours.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local remotes = ReplicatedStorage:WaitForChild("Remotes")
local attackRemote = remotes:WaitForChild("Attack")
local blockRemote = remotes:WaitForChild("Block")
local SWING_ANIMATIONS = { -- your published animation IDs, one per combo hit
"rbxassetid://0",
"rbxassetid://0",
"rbxassetid://0",
"rbxassetid://0",
}
local COOLDOWN = 0.45
local COMBO_RESET = 1.2
local tracks = {}
local lastSwing = 0
local combo = 0
local function loadAnimations(character)
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
tracks = {}
for i, id in SWING_ANIMATIONS do
local animation = Instance.new("Animation")
animation.AnimationId = id
tracks[i] = animator:LoadAnimation(animation)
end
end
if player.Character then
loadAnimations(player.Character)
end
player.CharacterAdded:Connect(loadAnimations)
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return -- the player was typing in chat or clicking a button
end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local now = os.clock()
if now - lastSwing < COOLDOWN then
return
end
if now - lastSwing > COMBO_RESET then
combo = 1
else
combo = (combo % #SWING_ANIMATIONS) + 1
end
lastSwing = now
local track = tracks[combo]
if track then
track:Play() -- animations on your own character replicate to everyone
end
attackRemote:FireServer()
elseif input.KeyCode == Enum.KeyCode.F then
blockRemote:FireServer(true)
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
blockRemote:FireServer(false)
end
end)
4. Test it
- Add a test dummy: in the Avatar tab, use the Rig Builder to insert an R15 rig and move it in front of your spawn.
- Press Play, walk up to the dummy and click. Its health should drop by 8, 8, 10, 14 as you combo.
- To see the hitbox while testing, add a temporary transparent, non-colliding part on the server at
root.CFrame * HITBOX_OFFSETwith sizeHITBOX_SIZE. Without that, you can't tell why a swing missed. - Test with two players: Test tab → Clients and Servers → 2 players. Hold F on one and attack with the other.
5. What to add next
- Hit timing. The server hits the moment it gets the event, before the animation reaches the hit frame. For heavier swings, wait with
task.delay(0.15, ...)on the server before the hitbox check, and check the attacker is still alive then. - Stun and knockback. Set a
Stunnedattribute on the target for a short time withtask.delay. For knockback, remember each player's own client owns their character's physics, so a push set on the server can be overwritten. Most games apply it with aLinearVelocityor by telling that player's client to apply it. - Effects and sounds. After a hit, use
attackRemote:FireAllClients(...)(or a separate RemoteEvent) to tell clients where to play a hit sound and particles. Keep effects on the clients and damage on the server. - Mobile and gamepad.
MouseButton1doesn't cover touch screens. UseContextActionService:BindActionwithcreateTouchButton = trueto get an on-screen attack button. - Swords and tools. Put the same client code in a
Tooland usetool.Activated. Keep the hitbox on the server.
Which hit detection to use
| Method | Good | Bad |
|---|---|---|
.Touched on the weapon |
Very easy | Misses fast swings and fires at odd times. Avoid it for combat. |
GetPartBoundsInBox on the server (above) |
Simple, hard to cheat | Can feel a little late for players with high ping |
| Raycasts along the blade each frame | Precise for swords | More code, and still needs server checks |
| Client hitbox, server checks it | Feels instant | The server must re-check distance, cooldown and line of sight, or exploiters can hit from across the map |
For most games, start with the server box. Move to client hitboxes with server checks only if players complain about lag.
Safety notes
- Never let the client send damage, a target or a position the server trusts. A RemoteEvent can be fired by an exploiter with any arguments. Check type, range and cooldown on the server, every time.
- Free models and "combat kits" from the Toolbox can hide backdoors. Before you publish, search every script in the model (Ctrl+Shift+F in Studio) for
require(followed by a number,getfenv,loadstringandsetfenv. Those can load someone else's code into your game. Delete scripts you don't understand. - Call
TakeDamageon the Humanoid, not on the Player. It also respectsForceFields, so spawn protection still works.
The SuperbulletAI route
SuperbulletAI is a desktop app for Windows and Mac that connects to Roblox Studio through a plugin and Rojo. You describe what you want in its chat and it writes the scripts into your project. It also has a marketplace of ready-made Roblox systems that it can install for you.
For combat, the marketplace has a Combat System framework with add-ons on top of it, including a Punch (melee) system and Parry & Block. A DamageHandler system is a prerequisite, and the app installs it first. You can watch a punch combo system go from an empty baseplate to working, with VFX, knockback, sounds and a test dummy, on the demo page.
How to get it:
- Download the app and follow the install guide to connect it to Studio.
- In the app's chat, ask for it, for example: "Install the combat system from the marketplace with the punch add-on, then add a test dummy in front of spawn."
- Answer the dialogs it shows: pick the library, confirm prerequisites, and upload the animations and sounds to your own Roblox account (it can do this for you with a Roblox Open Cloud API key you add once).
- Playtest. Then ask for changes in plain words: "Make the fourth hit do double damage and knock the target back."
Or skip the marketplace and prompt from scratch: "Make a sword combat system: 3-hit combo on left click, hold F to block, block takes 20% damage, hit detection on the server." It reads your existing code first, so it can wire combat into the health, stats or NPCs you already have.
Limits to know: installing animations needs them uploaded to your Roblox account, and you should review what it changes before you publish, as with any AI tool. Its code follows Superbullet's own project layout (a Knit-based framework), so it is easiest to extend inside a SuperbulletAI project.
