Now I could simply use GetPartsBoundInBox() or GetPartsInPart() here and loop through the resulting table and do what needs to be done, for example dealing damage on all the characters, but I’m trying to create a lingering hitbox, one that would successfully detect a character and go through with this process even if they were to be ‘hit’ by it in the last moment of it’s lifetime (0.15s)
EDIT: For the record, hitboxes is a variable, CreateHitbox() is a function in the module that basically creates, sets up and returns the hitbox as a part.
What is the best way of going about this? Any feedback and help would be greatly appreciated.
The hitbox lasts 0.15 seconds so that it ends in conjunction with the swing animation being played, wouldn’t want players to get after the animation ends after all.
The creation of the hitbox itself is fine, it gets the job done, what I’m trying to figure out is the best way to continuously detect everything touching the hitbox, it wouldn’t be as simple as a while true do loop right?
RunService is likely the best option for running the actual loop since this is on the client side, but I’d still need to know how to actually set things up here, an example would be really nice. With the way I have things set up, every detected character should have a remote fire to the server to deal the actual damage with the damage system, among other things.
Yeah I definitely recommend using GetPartsBoundInBox thanks to its customization. Since it’s on the client you can just use RunService.
local character = game.Players.LocalPlayer.Character;
local root = character:WaitForChild("HumanoidRootPart");
local params = OverlapParams.new();
params.FilterType = Enum.RaycastFilterType.Include;
params.FilterDescendantsInstances = {character}; -- we immediately add our character so it doesn't get detected by the hitbox
local clock = os.clock();
local connection = nil;
connection = game:GetService("RunService").PostSimulation:Connect(function(dt)
if os.clock() - clock >= 0.15 then -- if 0.15s have passed disconnect the event
connection:Disconnect();
return;
end;
local hitboxCFrame = root.CFrame * CFrame.new(0, 0, -3);
local hitboxSize = Vector3.new(6, 6, 6);
local parts = workspace:GetPartsBoundInBox(hitboxCFrame, hitboxSize, params);
for _, part in ipairs(parts) do
local hum = part.Parent:FindFirstChild("Humanoid");
if hum == nil then continue end;
params:AddToFilter(part.Parent); -- makes sure the enemy won't be hit multiple times
CombatRemote:FireServer(part.Parent); -- replace with your remote
end;
end);
Note that this would work on the server as well (besides the FireServer) but of course it would be way less responsive.
I wrote all this now without testing so if something errors let me know
I’d like to express my utmost and sincerest gratitude as this exact code hasn’t solved the problem in my case but certain key parts of it have helped me construct a functional solution.