BindableEvent supposedly not firing from modulescript

Hello, I am revamping the hitbox system for a game im working on. I decided to make a bindable event fire when a enemy character is detected and return said enemy character to the script that created the hitbox so the script can do things to the enemy character. But when I fire the remote and have the script use :Connect(), the bindableevent does not start my desired function.

also, it DOES hit. I checked with printing. I’m very new to doing stuff like this so please be nice!

modulescript:

local hitbox = {}
hitbox.__index = hitbox
local fs = require(game.ReplicatedStorage.Modules.FastSignal)
local Trove = require(game.ReplicatedStorage.Modules.Trove)
function hitbox.MakeHB(cframe,dmg,size,hitboxtime,showhitbox,char)
	
	local params = OverlapParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {char}
	local self = {}
	self.Trove = Trove.new()
	
	self.Hit = self.Trove:Construct(fs.new())
	if showhitbox ==  true then
		hitbox.Transparency = 0.5
	end
	if showhitbox == false then
		hitbox.Transparency = 1
	end
	hitbox.CFrame = cframe
	hitbox.CanCollide = false
	hitbox.Anchored = true
	hitbox.Material = "Neon"
	hitbox.Size = size
	local mainpart = Instance.new("Part",workspace)
	mainpart.CFrame = hitbox.CFrame
	mainpart.CanCollide = false
	mainpart.Anchored = true
	mainpart.Size = hitbox.Size
	self.Trove:AttachToInstance(mainpart)
game.Debris:AddItem(mainpart,hitboxtime)
	
	local results = game.Workspace:GetPartBoundsInBox(hitbox.CFrame,hitbox.Size,params)
	
--	local results = GetTouchingParts(mainpart)
	local deb = false
	for _,v in pairs(results) do
		if v.Parent ~= char then
			
			if v.Parent:FindFirstChild("Humanoid") then
				local enemychar = v.Parent
				if deb == false then
					self.Hit:Fire(enemychar)
					print("ok")
					deb = true
					
				end
			end
		end
		end
	return setmetatable(self,hitbox)
	
	
	
end


return hitbox

server script:

local hitbox = hitboxmodule.MakeHB(hrp.CFrame,5,Vector3.new(8,8,8),0.5,false,char)
		
	hitbox.Hit:Connect(function(enemy)
		print("heyo")
	end)
2 Likes

Change this

hitbox.Hit:Connect(function(enemy)
	print("heyo")
end)

to

hitbox.Hit.Event:Connect(function(enemy)
	print("heyo")
end)
2 Likes

tried this, it just prints a error. Thanks for trying to help though

1 Like

Can you show the printed error?

1 Like

the error is attempt to index nil with ‘Connect’.

Is the “Hit” variable returned by the trove module a bindable event? If it is you’ll need to index “Event” and connect that to the function for it to work.

1 Like

I’m pretty sure this is because you fire the Hit signal before you’ve established a connection to it. To fix this, you can separate your hitbox function into a creation function that makes the part and a second function that runs GetPartBoundsInBox with the part. You would then place your connection in between the two, like this:

local hitbox = hitboxModule.Create(-- params)
hitbox.Hit:Connect(function()
    print("hit")
end)
hitbox:Scan() -- Runs everything below and including "local results = game.Workspace:GetPartBoundsInBox(hitbox.CFrame,hitbox.Size,params)" in your code
1 Like

Oh, I just noticed that. That could be your solution.

1 Like

this fixed it, thank you so much!

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