-
What do you want to achieve? Keep it simple and clear!
I want to send a simple event through a bindable event that contains two arguments, one for part and another for humanoid. Fire and Event are both present in module scripts running from the server side. -
What is the issue? Include screenshots / videos if possible!
The .Event event is not firing, thus breaking the scripts. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried researching Signal classes such as quenty’s but I feel they are essentially bindable events in their core.
For more info, I’m making a hitbox system for my game. When the hitbox detects a part whose parent has a humanoid, and is not part of debounce table, it sends an event through the aforementioned bindable event. But when I try to receive the event through the .Event event, It does not register.
Hitbox Module(module script)
local Hitbox = {}
Hitbox.__index = Hitbox
local function CreateVolumetricHitbox(size:Vector3, cframe:CFrame | Instance?, offset:CFrame):BasePart?
local hitbox = Instance.new("Part")
hitbox.Size = size
hitbox.CFrame = cframe * offset
hitbox.Transparency = 0
hitbox.CanCollide = false
hitbox.Anchored = true
hitbox.Parent = workspace
return hitbox
end
function Hitbox.Create(hitboxType:number | string, params:RaycastParams?)
local self = {}
if typeof(hitboxType) == "number" then
if hitboxType == 1 then
warn("Raycast based hitbox detection isn't supported yet.")
self.HitboxType = "Raycast"
elseif hitboxType == 2 then
self.HitboxType = "Spatial"
end
elseif typeof(hitboxType) == "string" then
if hitboxType == "Raycast" then
warn("Raycast based hitbox detection isn't supported yet.")
self.HitboxType = "Raycast"
elseif hitboxType == "Spatial" then
self.HitboxType = "Spatial"
end
end
self.CFrame = CFrame.new()
self.Offset = CFrame.new()
self.Size = Vector3.new(1, 1, 1)
self.OverLapParams = OverlapParams.new()
self.Active = false
self.Touched = Instance.new("BindableEvent")
return setmetatable(self, Hitbox)
end
function Hitbox:Detect(duration:number)
if self.Active then return; end
local detectedParts = {}
local hitParts = {}
local debounce = {}
self.Active = true
if self.HitboxType == "Spatial" then
local hitbox = CreateVolumetricHitbox(self.Size, self.CFrame, self.Offset)
local connection; connection = game:GetService("RunService").Heartbeat:Connect(function()
hitbox.CFrame = self.CFrame
detectedParts = workspace:GetPartsInPart(hitbox, self.OverLapParams)
for i, v:Instance in detectedParts do
if not table.find(hitParts, v) and v.Parent and v.Parent:FindFirstChildOfClass("Humanoid") then
table.insert(hitParts, v)
end
end
for i, v in hitParts do
if not table.find(debounce, v.Parent.Humanoid) then
self.Touched:Fire(v, v.Parent.Humanoid)
print("fired")
table.insert(debounce, v.Parent.Humanoid)
task.spawn(function()
task.wait(1)
table.remove(debounce, table.find(debounce, v.Parent.Humanoid, 1))
end)
end
end
end)
task.wait(duration)
self.Active = false
connection:Disconnect()
connection = nil
hitbox:Destroy()
end
end
return Hitbox
Object Module(module script, but what I am about to show is only a part of it as this part is the only one which deals with the hitbox stuff.)
["Experimental"] = {
activate = function(self)
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Exclude
overlapParams.FilterDescendantsInstances = {self.ObjectContainer}
local HitboxModule = require(script.Parent.Hitbox)
local hitbox = HitboxModule.Create(2)
hitbox.Size = self.Object.Size
hitbox.OverLapParams = overlapParams
game:GetService("RunService").Heartbeat:Connect(function()
hitbox.CFrame = self.Object.CFrame
end)
hitbox.CFrame = self.Object.CFrame
local swinganim = self.ObjectContainer.Parent:FindFirstChild("Humanoid"):FindFirstChild('Animator'):LoadAnimation(clubswing)
swinganim:Play()
hitbox:Detect(1)
hitbox.Touched.Event:Connect(function(hit, hum)
print("e")
Damage(self.ObjectContainer.Parent, 45, hum, false)
end)
end;
["COOLDOWN"] = 0.3;
};
in this script the activate function is a function that runs when the tool is activated.