Making a battlegrounds-like game

Hello!

I am trying to make a game kinda like a battlegrounds game. I am just struggling on how/where (client/server) to load animations, do hitboxes and damage, handle stuns, and checks.

I want my game to be as lag free as possible, but I don’t want it vulnerable to exploiters.

I also want to do other checks like making it so the player can’t attack while underwater, and other things, but I don’t know where.

Thanks!

2 Likes

u should handle the animations on the client and handle hitboxes, stuns, and most checks on the server. animations automatically replicate to other players. to prevent lag, handle effects and most visuals on the client.

underwater checks should be done on both the client and the server. on the client, make it so that the player’s attack inputs aren’t even considered. (i.e. if isUnderwater then return end) then perform another check on the server just to make sure.

1 Like

Well first things first you got to understand a lot of things before you begin making complex combat systems like battlegrounds. Remote Events, server sanity checks, how hitboxes and connections would work and what not. But I’ll explain anyway. (This is how I see many people do it, and it hasn’t seemed to fail anyone just yet.)

There’s a list of things you’ve got to do.

  • Establish States, (Blocking, Attacking)
  • Establish Responsive Hitboxes (Client Sided with Server Sanity Checks) or just use Muchacho hitbox.
  • Establish Damage (ALWAYS SERVERSIDED)
  • Establish Client → Server communication, (Inputs.)
  • And then skills and linking them to inputs.

---------- INPUTS

The client side will handle inputs, (cause only the client can lol.)
Establish your inputs on the client using CAS or UIS your choice.

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Input, GPE) -- the parentheses stores the passed arguments.
         if GPE then
            return;
         end

         if Input.UserInputType == Enum.UserInputType.MouseButton1 then
                -- code here
         end
end)
local ContextActionService = game:GetService("ContextActionService")

local function M1()
	--- CODE
end

ContextActionService:BindAction("M1", M1, false, Enum.UserInputType.MouseButton1) -- just put another hotkey for more hotkeys.)

— STATES

I preferably do it a different way, (which is probably worse to be honest but it’s been alright for me right now, THOUGH. This is a simpler way.

Create a folder named “CharacterStates” in replicated Storage, and put every state you want in there using Bool Values (object) - Also you’d wanna put a few StringValues and maybe a few number values to track their Ultimate bar, selected character, Combo Count, etc.

And on a server script you’d wanna do something like this.

local StateFolder = (path.to.StateFolder)
local Players = game:GetService("Players")

workspace.ChildAdded:Connect(function(child)
    if child:IsA("Model") and child:FindFirstChildOfClass("Humanoid") then
          if not child:FindFirstChild("CharacterStates") then
                 local newFolder = StatesFolder:Clone()
                 newFolder.Parent = child -- puts a clone of the states folder into the character.
          end
    end
end)

Players.PlayerAdded:Connect(function(Player)
	local Char = Player.Character or Player.CharacterAdded:Wait()
	
	if not Char:FindFirstChild("CharacterStates") then
		local newFold = States:Clone()
		newFold.Parent = Char
	end
end)

— Animations

Animations can be handled on Server and Client it really doesn’t matter as long as you preload them. To preload them you want to make a new local script, (put it in replicated first) and put a folder beneath it. Store all the animations in that folder Organize it how you want and what not, doesn’t matter.

Afterwards, put this code into the local script.

local ContentProvider = game:GetService("ContentProvider")

local assetids = {}

for Key,Value in pairs(script:GetDescendants()) do
	if Value:IsA("Animation") or Value:IsA("Sound") then
		table.insert(assetids, Value)
	end
end

ContentProvider:PreloadAsync(assetids)

— Hitboxing.

Honestly, just use muchacho hitbox, it’s already full fledged and pretty good. Until you learn how to make your own it’s your best bet. (only on the server though)

— Connection

After a click, you’d want to fire a remote to the server and tell the remote what action you’re doing, to start a hitbox, and wait for a touch. (Becomes simple with muchacho hitbox.)

– Damage

You can use a bindable event or a module to do damage; By sending the player through the event or through a function in a module.

You’d want to first iterate through all of the created states, but first, make sure they even have the folder.

(An Example if it was a module)

local DamageService = {}

function DamageService.Hit(Attacker:Model, Target:Model, Ignores:{}) : string
	assert(Attacker:FindFirstChild("CharacterStates"), "The attacker not have his characterstates folder, hence he should not be fully registered.")
	assert(Target:FindFirstChild("CharacterStates"), "The target not have his characterstates folder, hence he should not be fully registered.")
	
	local AttackerStates = Attacker:FindFirstChild("CharacterStates") :: BoolValue
	local TargetStates = Target:FindFirstChild("CharacterStates") :: BoolValue
	
	local AttackerRoot = Attacker:FindFirstChild("HumanoidRootPart")
	local TargetRoot = Target:FindFirstChild("HumanoidRootPart")
	
	local Distance = TargetRoot.CFrame:Inverse() * AttackerRoot.CFrame
	
	local IsBehind = false
	
	if Distance.Z > 1.5 then
		IsBehind = true
	end
	
	if TargetStates.Blocking.Value == true and not table.find(Ignores, "Blocking") and not IsBehind  then
		return {"Invalid", "Blocking", Target}
	end
	
	if TargetStates.IFrames.Value == true and not table.find(Ignores, "IFrames") then
		return {"Invalid", "IFrames", Target}
	end
	
	-- add any other states that would prohibit someone from hitting someone else or cause an action to occur.
	
	return {"Valid", "None", Target}
end

return DamageService

— END

That’s about all the pointers and tips I can give you without making a literal full fledged tutorial. There are MANY tutorials on how to handle other things such as Combos and what not. I decided to write this out cause GOD it took me so long to find out how to handle combat.

6 Likes

Wow. Thank you both so much! I think this will help me a ton.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.