Bullet Collision not detected

I’m making a simple mini-game where a player can shoot bullets at ballons to pop them. The idea is simple: When the balloon is Touched, we check if the other part that touched it has a name of bullet, then we also check if they have the same color.

Balloon event handler:

local function onCollision(otherPart, balloon)
	print("Collision detected!")
	-- check if the other object is a bullet
	if otherPart.Name == "Bullet" then
		print("Bullet detected!")
		-- check if the colors of the balloon and the bullet match
		if balloon.Color == otherPart.Color then
			-- destroy the balloon
			balloon:Destroy()
		end
	end
end

sphere.Touched:Connect(function(otherPart)
        onCollision(otherPart, sphere)
end)

Gun tool:

local gun = script.Parent
Debris = game:GetService("Debris")
local playerChar = gun.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerMouse = player:GetMouse()

gun.Activated:Connect(function()
	local bullet = Instance.new("Part")
	bullet.Name = "Bullet"
	bullet.Size = Vector3.new(1, 1, 1)
	bullet.Shape = Enum.PartType.Ball
	bullet.Material = Enum.Material.Plastic
	bullet.Color = Color3.fromRGB(117, 0, 0)
	bullet.Parent = workspace
	bullet.CanCollide = true
	print("bullet created")
	bullet.CFrame = gun.Nozzle.CFrame:ToWorldSpace(CFrame.new(2, 0, 0))

	local directionVector = CFrame.lookAt(bullet.Position, playerMouse.Hit.Position).LookVector
	local velocityVector = directionVector * 120

	bullet:ApplyImpulse(velocityVector)
	Debris:AddItem(bullet, 5)
end)

I’m not sure why the balloon’s are not disappearing. The “Bullet detected!” print statement never executes.

2 Likes

I would definitely go and check to see if this condition is actually true
Just put this in a print statement and see if the color actually matches

print("Bullet detected!", balloon.Color == otherPart.Color)

You should use FastCast, I use it for things that are thrown and need to land on the ground in my game. It always picks up objects in front of your bullet 100% of the time too.

Seems like the first condition is not even true; the bullet’s name is registered as “Part” even though I explicitly set it as “Bullet” in the tool script. I wonder why? :thinking: