(Help) :Touched() Function not triggering

In my game, I want to have a weapon in my game that when clicked, shoots a bullet that damages (fair enough), however, when I shoot a player or NPC, there are “blind spots”, the NPC will not be hurt whatsoever even though the bullet clearly touched the humanoid. I have tried looking on the developer forum but have not found a good solution.


You can see the large trail of bullets go to the NPC, but when they connect it only dealt a bit of damage instead of mowing down the humanoid.

script when button is held down:

gun.Equipped:Connect(function(mouse)
	equipted = true
	player.PlayerGui.HUD.Ammo.Visible = true
	updateammo()
	mouse.Button1Down:Connect(function()
		shooting = true
		while shooting do
			if gun.Ammo.Value > 0 then 
				wait()
				remoteevent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.Position)
				gunshot:Play()
				gun.Ammo.Value = gun.Ammo.Value - 1
			else
				empty:Play()

			end

		end
	end)
	mouse.Button1Up:Connect(function()
		shooting = false
	end)
	
	mouse.Button2Down:Connect(function()
		local camera = game.Workspace.CurrentCamera
		camera.FieldOfView = 40
		
	end)
	mouse.Button2Up:Connect(function()
		local camera = game.Workspace.CurrentCamera
		camera.FieldOfView = 70
	end)

end)

Script when bullet is created:

local replicatedstorage = game:GetService("ReplicatedStorage")
local remoteevent = replicatedstorage:WaitForChild("ShotEvent2")
local serverstorage = game:GetService('ServerStorage')

remoteevent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
	--print(gunPos)
	--print(mosPos)
	
	local bullet = Instance.new("Part")
	bullet.Name = "Bullet"
	bullet.Parent = game.Workspace
	bullet.Position = gunPos
	bullet.Shape = Enum.PartType.Cylinder
	bullet.Size = Vector3.new(0.5, 0.25, 0.5)
	--bullet.Size = Vector3.new(1,1,1)
	--bullet.CanCollide = false
	bullet.BrickColor = BrickColor.new("Gold")
	
	local damagescript = serverstorage:FindFirstChild("Damage2"):Clone()
	damagescript.Parent = bullet
		
	local attacker = Instance.new("StringValue")
	attacker.Name = "Attacker"
	attacker.Parent = bullet
	attacker.Value = player.Name
	
	local distance = (mosPos - gunPos).magnitude
	local speed = 999
	bullet.CFrame = CFrame.new(gunPos, mosPos)
	bullet.Velocity = bullet.CFrame.LookVector * speed
	bullet.Orientation = gunOr + Vector3.new(0, -90, 0)
	print(speed)
	
	game:GetService("Debris"):AddItem(bullet, 2)
	
end)

Damage2 (damaging script:

local bullet = script.Parent
local hitsound = game.Workspace.Click
local headshot = game.Workspace.Headshot

local function player_check(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
		if otherPart.Name == "Head" then
			humanoid:TakeDamage(20)
			headshot:Play()
		else
			humanoid:TakeDamage(10)
			hitsound:Play()
			
		end
		--print("bullet connected")
		local player = game.Players:FindFirstChild(humanoid.Parent.Name)
		if player then
			local tag = player:FindFirstChild("Killer")
			if tag then
				tag.Value = bullet.Attacker.Value
				bullet:Destroy()
			end
		end
	end
end

bullet.Touched:Connect(player_check)

Thank you for reading

3 Likes

.Touched event is slow and when you are using it for a small part (“bullet”) that goes fast, .Touched event will not detect most of the things the bullet touches, using .Touched events for hitboxes are very bad.

" Touch Events: The main reason why you should, under ANY circumstance NOT use this is because it isn’t that good at detecting things. For example. Touch events have TONS of issues, server delays, and much more. So using this for a hit box isn’t the best idea"

I recommend using ray casts for guns. (Raycast Hitbox 4.01: For all your melee needs!)

4 Likes

As @Dev_Sie said, .Touched is bad for quickly moving objects. The fact that you have a small bullet (.5, .25, .5) moving at 999 studs/second means that they aren’t always ‘there’ when they need to hit something.