{SOLVED} Why is my hitbox not firing the touched event?

Hello guys, another problem that i have

I’m making a soccer game inspired by inazuma eleven, i used the muchacho hitbox for the tackle, but for some reason, the module script touched event in my server script of the tackle is not working, maybe it has to do something with the ball? I don’t know, but it has can collide and can touch enabled, i don’t see what is the problem, here’s my script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local TackleEvent = ReplicatedStorage.Events:WaitForChild("TackleEvent")
local HitboxModule = require(game.ServerStorage:WaitForChild("MuchachoHitbox"))

local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {workspace:WaitForChild("Ball")}

local Character = nil
local Humanoid = nil
local HRP = nil

local LinearVelocity = nil
local TackleTrack:AnimationTrack = nil
local TackleCooldown = 3
local TackleDB = false
local TackleAnim = script:WaitForChild("Tackle") -- old id: 98806224382281

TackleEvent.OnServerEvent:Connect(function(Player)
	if TackleDB == true or Player.Character.Energy.Value <= 2 then return end

	local IsSprintingValue = Player.Character:FindFirstChild("IsSprinting") 

	TackleDB = true
	Character = Player.Character
	Humanoid = Character:WaitForChild("Humanoid")
	HRP = Character:WaitForChild("HumanoidRootPart")

	TackleTrack = Humanoid.Animator:LoadAnimation(TackleAnim)

	LinearVelocity = Instance.new("LinearVelocity")
	Humanoid.AutoRotate = false
	Humanoid.HipHeight = -1.8

	Player.Character.CanRecover.Value = false
	Player.Character.Energy.Value -= 2

	LinearVelocity.ForceLimitsEnabled = true
	LinearVelocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
	LinearVelocity.MaxAxesForce = Vector3.new(math.huge, 0, math.huge)
	LinearVelocity.Attachment0 = HRP:FindFirstChild("RootAttachment")
	LinearVelocity.Parent = HRP

	TackleTrack:Play()
	TackleTrack:GetMarkerReachedSignal("Stun"):Connect(function()
		TackleTrack:AdjustSpeed(0)
	end)
	
	local hitbox = HitboxModule.CreateHitbox()
	
	hitbox.Shape = Enum.PartType.Ball
	hitbox.DetectionMode = "ConstantDetection"
	hitbox.Size = 5
	hitbox.CFrame = HRP
	hitbox.Offset = CFrame.new(0,2,-5.5)
	hitbox.OverlapParams = params
	
	hitbox:Start()
	
	hitbox.Touched:Connect(function(hit, humanoid)
		hitbox:Stop()
		workspace.Ball.Anchored = true
		workspace.Ball.CanCollide = false
		workspace.Ball.CFrame = HRP.CFrame
		local Motor6D = Instance.new("Motor6D", Character)
		Motor6D.Part0 = HRP
		Motor6D.Part1 = workspace.Ball
	end)

	for i = 40, 1, -1 do
		LinearVelocity.VectorVelocity = HRP.CFrame.LookVector * i
		task.wait(0.02)
	end
	
	task.wait(0.6)

	TackleTrack:AdjustSpeed(1)

	if IsSprintingValue and IsSprintingValue.Value == false then
		Player.Character.CanRecover.Value = true
	end
	hitbox:Stop()
	Humanoid.HipHeight = 0
	LinearVelocity:Destroy()
	Humanoid.AutoRotate = true
	task.wait(TackleCooldown)
	TackleDB = false
end)

If you’re curious of what my explorer looks like, here:
Screenshot_1

Using Enum.RaycastFilterType.Include means that the hitbox won’t be able to detect anything but the ball, so you’ll need to use Enum.RaycastFilterType.Exclude if you want the hitbox to detect everything except the ball

I want it only to detect the ball, i don’t want it to detect anything BUT the ball, it just doesn’t work even when i completely touch the ball

Oh and also, nothing prints in the output, but if i remove the params, for some reason, it works??? I actually dont understand at all, but if i change the params to not touch me, it doesn’t work, i understand nothing at all

If the hitbox isn’t able to detect anything other than the ball itself, then how will it detect when you touch it?

The fact that it works if you remove the RaycastParams is proof of what I’m trying to say, the hitbox needs to be able to detect player characters in-order to work as you desire, otherwise the hitbox will never detect anything

Event tocuhed is not reliable, that is, I personally consider it obsolete. It is not as good at determining anything in the field. It is better to use workspace:GetPartBoundsInBox(). It defines what objects are inside the Part.

I wrote a script for you, the script creates a hitbox which removes the hitbox when a ball is detected

local RS = game:GetService("RunService")
local Ball = workspace:WaitForChild("Ball")

local overlampParameters = OverlapParams.new()
overlampParameters.FilterType = Enum.RaycastFilterType.Include
overlampParameters.FilterDescendantsInstances = {Ball}

local hitboxTransparency = .5 -- hitbox transparency
local x,y,z = 0,  1.65,  1.5 -- hitbox offset position

local hitbox = Instance.new("Part")
hitbox.Shape = Enum.PartType.Ball
hitbox.Size = Vector3.new(5,5,5)
hitbox.CanCollide = false
hitbox.Massless = true
hitbox.Transparency = hitboxTransparency
hitbox.Color = Color3.new(1, 0.0973373, 0.181186)

local w = Instance.new("Weld")
w.Part1 = hitbox
w.Part0 = Character.HumanoidRootPart
w.C1 = CFrame.new(x,y,z)
w.Parent = hitbox
hitbox.Parent = workspace

local detecting
detecting = RS.Stepped:Connect(function(dt)
	if not hitbox.Parent or Character.Humanoid.Health <= 0 then
		if hitbox.Parent then
			hitbox:Destroy()
		end
		warn("ball succefly detected!")
		detecting:Disconnect()
	else
		local currBall = nil
		local result = workspace:GetPartBoundsInBox(hitbox.CFrame,hitbox.Size,overlampParameters)
		if result then
			for i,v in pairs(result) do
				if v.Name == "Ball" then
					currBall = v
					hitbox:Destroy()
				end
			end
		end
	end
end)
1 Like

Also, for better gameplay, I recommend to put my script in local script, and after touching, signal RemoteEvent to the server script, which will check if the player is close to the ball using:

local distance = (HumanoidRootPart.Position - Ball.Position).Magnitude
if distance < 8 then
	warn("ball can be attached!")
-- // Continue attach function here //
end

The touched event of the module that im using automatically uses spatial query, i just don’t know why it isn’t working, i tried changing the shape of the ball but not even that works, i actually don’t know what is happening

I think it has something to do with the ball, because when i do that with the character it works very cool but when with the ball it doesn’t work

I just fixed altering the module detection mode to hitparts:

local Params = OverlapParams.new()
	Params.FilterType = Enum.RaycastFilterType.Include
	Params.FilterDescendantsInstances = {workspace.Ball}
	
	hitbox.DetectionMode = "HitParts"
	hitbox.Size = Vector3.new(6, 6, 6)
	hitbox.CFrame = HRP
	hitbox.Offset = CFrame.new(0,2,-5.5)
	hitbox.OverlapParams = Params