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)