.Touched - 1 anchors part and 1 unanchored part - not firing

Hi,

I have a rocket model. It’s two parts welded, grouped under a model. Primary part is set and the primary part’s can collide and can touch is on. They are not anchored.
I have a wall that does the same. It’s anchored.

If I call .touched from the rocket when it hits the wall, nothing happens since it simply doesn’t happen. (Visually it does). Note that the rocket moves via body velocity (or roblox physics).
If I call .touched from the anchored wall, however, it does fire and prints the object that hit it.
How do I make it so I can detect from the un anchored part?

1 Like

You should provide more details, like showing the code you used in the rocket and show images of the rocket’s properties. There’s nothing anyone can do because, according to the way you described it, it is supposed to work, and there shouldn’t be any bug.

Local script for person who fires it:

local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("FireRocketEvent")

local rocketModel = ReplicatedStorage.Rocket
local rocket_explosion = ReplicatedStorage.Rocket_explosion_1

local reloadTime = 2 -- Time in seconds between each shot
local canFire = true
local rocketClone = rocketModel:Clone()

local function playparticles(hit)
	print("reached")
	--print("Rocket touched:", hit.Name)
	--print(rocketClone.PrimaryPart.Name)
	local position = rocketClone.PrimaryPart.Position
	rocketClone:Destroy()
	local partclone = rocket_explosion:Clone()
	partclone.Position = position
	partclone.Parent = game.Workspace
	for i,v in ipairs(partclone.Attachment:GetChildren()) do
		--print(v.Name)
		v:Clear()
		wait()
		v:Emit(50)
	end
end
local function fireRocket()
	
	--print("clicked")
	--print(remoteEvent)
	if canFire then
		
		--canFire = false
		local x = mouse.Hit.p
		local y = script.Parent.rocket_part_1.CFrame
		--print(x)
		--print(y)
		-- Send a request to the server to fire the rocket
		remoteEvent:FireServer(x, y)
		rocketClone = rocketModel:Clone()
		rocketClone.PrimaryPart = rocketClone["Cylinder.001_Cylinder.003"]
		rocketClone.PrimaryPart.CanTouch = true
		rocketClone.PrimaryPart.CanQuery = true
		rocketClone:SetPrimaryPartCFrame(y) -- Adjust as necessary
		rocketClone.Parent = game.Workspace

			-- Get the direction to fire towards
		local direction = (x - rocketClone.PrimaryPart.Position).unit
			-- Add velocity to the rocket
		local bodyVelocity = Instance.new("BodyVelocity")
		bodyVelocity.Velocity = direction * 100 -- Adjust the speed as needed
		bodyVelocity.Parent = rocketClone.PrimaryPart
		-- Optionally, add a script to handle rocket explosion on collision

		-- Wait for the reload time before allowing to fire again
		--wait(reloadTime)
		canFire = true
	end
	
end

rocketClone.PrimaryPart.Touched:Connect(playparticles)


tool.Activated:Connect(fireRocket)

Could it be because it’s a local script? Not sure if that matters?

When you activate the Tool, you redefine the rocketClone variable to rocketModel:Clone(). The reason it doesn’t work is because you’re connecting Touched to the rocketClone that wasn’t made by the fireRocket function. Connect the Touched event in the fireRocket function instead.

Also, from what I see, you’re uneccessarily defining a rocketClone variable before the fireRocket function. Just define it inside the function.

2 Likes