Hitlist returning empty

why does the hitlist return empty? i tested it on both a player and a dummy

local rs = game:GetService("ReplicatedStorage")

local stunnedevent = rs:WaitForChild("StunnedEvent")

local HitboxModule = require(rs:WaitForChild("Modules").HitboxModule)

stunnedevent.OnServerEvent:Connect(function(player)
	local hitplayers = HitboxModule.Hitbox(player,CFrame.new(0,0,-2.5),Vector3.new(5,5,5),10)
	local bloodvfx = rs:WaitForChild("BloodVfx"):Clone()
	local chr = player.Character
	local hrp = chr.PrimaryPart
	bloodvfx.Parent = workspace
	bloodvfx.CFrame = hitplayers.CFrame
	task.wait(5)
	bloodvfx:Destroy()

	
end)



module script is

local module = {}

module.Hitbox = function(player,Cframe,Size, Damage)
	local rs = game:GetService("ReplicatedStorage")
	local chr = player.Character
    local hitboxCFrame = chr.PrimaryPart.CFrame * Cframe
    local hitboxSize = Size
    local damage = Damage
    local hitbox = rs.Hitbox:Clone()
    hitbox.Parent = workspace
    hitbox.CFrame = hitboxCFrame
    hitbox.Size = Vector3.new(hitboxSize, hitboxSize, hitboxSize)
    local hitcontent = workspace:GetPartBoundsInBox(hitboxCFrame, hitboxSize)
    local hitlist = {}

    for _,v in pairs(hitcontent) do
	    if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= chr and not table.find(hitlist, v.Parent) then
		table.insert(hitlist, v.Parent)
		v.Parent.Humanoid:TakeDamage(damage)
		print(v.Parent.Name)
	    end
	end
	if #hitlist == 0 then
		print("hitlist is empty!")
	else
		return hitlist
	end

end




return module

The size is reverting to 0, as you are providing Vector3s as the parameters in Vector3.new()

Try doing just

hitbox.Size = hitboxSize

and it SHOULD resolve your issue.

unfortunately i still have this error

Is it printing out “Hitlist is empty”?

yea (word count), also when i try it on player 2 it doesn’t even print anything not even hitlist is empty when I try it on a dummy it prints out hitlist is empty

Can you please print out the value of hitplayers, as well as hitlist?

sorry for the late reply

i added a print function to the code
and also moved the hitlist is found print function above the return hitlist

local rs = game:GetService("ReplicatedStorage")

local stunnedevent = rs:WaitForChild("StunnedEvent")

local HitboxModule = require(rs:WaitForChild("Modules").HitboxModule)

stunnedevent.OnServerEvent:Connect(function(player)
	local hitplayers = HitboxModule.Hitbox(player,CFrame.new(0,0,-2.5),Vector3.new(5,5,5),10)
	print(hitplayers)
	local bloodvfx = rs:WaitForChild("BloodVfx"):Clone()
	local chr = player.Character
	local hrp = chr.PrimaryPart
	bloodvfx.Parent = workspace
	bloodvfx.CFrame = hitplayers.CFrame
	task.wait(5)
	bloodvfx:Destroy()

	
end)

updated module script is below

local module = {}

module.Hitbox = function(player,Cframe,Size, Damage)
	local rs = game:GetService("ReplicatedStorage")
	local chr = player.Character
    local hitboxCFrame = chr.PrimaryPart.CFrame * Cframe
    local hitboxSize = Size
    local damage = Damage
    local hitbox = rs.Hitbox:Clone()
    hitbox.Parent = workspace
    hitbox.CFrame = hitboxCFrame
	hitbox.Size = hitboxSize
    local hitcontent = workspace:GetPartBoundsInBox(hitboxCFrame, hitboxSize)
    local hitlist = {}

    for _,v in pairs(hitcontent) do
	    if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= chr and not table.find(hitlist, v.Parent) then
		table.insert(hitlist, v.Parent)
		v.Parent.Humanoid:TakeDamage(damage)
		print(v.Parent.Name)
	    end
	end
	if #hitlist == 0 then
		print("hitlist is empty!")
	else
		print("hitlist is Found!")
		return hitlist
	end

end




return module

Now whenever I hit the dummy is says hitlist is found and prints out


the error is still there.

secondly whenever I hit the player it doesn’t even print anything and spawns the VFX at the dummy not at the player, it damages the player as intended though.

I’ve edited your module script a bit so that it’s much cleaner and easier to read.
Changed script:

local module = {}

module.Hitbox = function(Character:Model, CFrameOffset:CFrame, Size:number, Damage:number, VfxPart:BasePart)
	local Hrp = Character:FindFirstChildOfClass("Humanoid").RootPart
	
	local Hitbox = workspace:GetPartBoundsInBox(Hrp.CFrame * CFrameOffset, Vector3.one * Size)
	
	local Filtered = {}
	
	for _, Parts in Hitbox do
		local PossibleCharacter = Parts.Parent
		
		if PossibleCharacter == Character or table.find(Filtered, PossibleCharacter) or not PossibleCharacter:IsA("Model") then continue end
		
		local Humanoid = PossibleCharacter:FindFirstChildOfClass("Humanoid")
		if not Humanoid then continue end
		
		local VfxClone = VfxPart:Clone()
		VfxClone.CFrame = Humanoid.RootPart.CFrame
		VfxClone.Parent = workspace
		
		Humanoid:TakeDamage(Damage)
		
		table.insert(Filtered, PossibleCharacter)
		task.delay(5, game.Destroy, VfxClone)
	end
	
	table.clear(Filtered)
end

return module

I’ve pretty much made it simpler for you because size is now just a number and you can directly pass in the vfx part.

How you would use the changed module script in your server script:

local rs = game:GetService("ReplicatedStorage")

local stunnedevent = rs:WaitForChild("StunnedEvent")

local HitboxModule = require(rs:WaitForChild("Modules").HitboxModule)

stunnedevent.OnServerEvent:Connect(function(player)
	local Character = player.Character
	local bloodvfx = rs:WaitForChild("BloodVfx")
	
	HitboxModule.Hitbox(Character, CFrame.new(0,0,-2.5), 5, 10, bloodvfx)
end)

Thank you so much bro it works nicely, only issue is that the dmg repeats itself a bunch, like 6x other then that, there is no issue

Why are you doing hitboxes on the server? This puts unnecessary load on the server, not only that, it’ll be delayed which can lead to a non smooth game experience.

couldnt exploiters, have access to the hitboxes and dmg if it was on the client side

I updated the module code so it should work fine now. I’m programming from my phone so it’s kind of hard to track the different things I’m doing. So just go back to that post and copy the updated module code

@lgotanintendoswitch That’s not my option. He began with it being on the server so I’m helping him with improving what he already had. @InactiveVan2 it’s a good suggestion to keep in mind too.

1 Like

Depends, if you passed them from the Client without confirming stuff on the server, it could definitely be exploitable. This was an issue with phantom forces back in the day.