I’m quite new to Lua and to Roblox Studio, however I’ve been working on a basic combat system for a game and I’ve reached the point where I can generate a hitbox in front of the player using this:
I’ve looked around the forum a bit but I haven’t yet found a solution which is clear, but what I’m aiming to do is make any “Enemy” model touching this take some damage. Any advice?
There’s three main options you can pick when making hitboxes:
Magnitude: Magnitude checks are done by checking the distance between the origin of the hitbox and the potential targets, resulting in a sphere-like shape. They’re very simple and I would reccomend using them if you don’t need hitboxes in a specific shape.
GetPartBoundsInBox: Bounds box checks are more like you’d see in a 2D fighting game. They use a CFrame and Size to return all intersecting parts. If you need attacks to be precise about where they hit, this is the way to go.
Raycasts: Raycasts are only really used for super-precise hitboxes, like if you’re trying to replicate Morhau’s combat. The main problem is that since the hitbox is determined by the animation, you will need to change the animation if you want to change the hitbox’s trajectory.
Hi Randomness!! I wrote a quick, simple script that should more or less do what you want. Let me know if you have any questions!
local hitbox = repStore.CharTest001.M1hitboxT001:Clone()
local damage = --// whatever number of damage you want to do per hit
hitbox.Touched:Connect(function(Part)
if Part.Parent.Name == "Enemy" then
Part.Parent.Humanoid.Health -= damage
end
end)