Detecting if Nuke is touching the baseplate

hmm… I tried print(“test”) after the touched event but it doesn’t output, strange huh? which means something must be wrong with the touched event

	G = Nuke.Touched:Connect(function(hit)
		print("test")
		if hit.Name == "Baseplate" then
			print("Nuke is touching the baseplate!")
		end
	end)

its not detecting because you are dealing with anchored parts, touched stops working when you involve anchored parts thats why touched event is horrible and its also unresponsive.

local nuke = game.Workspace:FindFirstChild("Nuke")

Nuke.Touched:connect(function(hit)
       if hit.Name == "Baseplate" then
             print("test")
       end
end)

I am a novice scripter and I have no experience in raycast tho

hold on my brain is broken rn i havent slept for a while im gonna make a test in studio and report back

Well, umm… thank you so much for helping me I really appreciate it. But rn is really late for me its 3:17am SGT and I had to sleep haven’t slept for like 10-12 hours since 11am in the morning. I guess I will reach out to you tomorrow. GN

local missile = script.Parent

local debounce = false

missile.Touched:Connect(function(hit)
	if hit.Name == "Part" and not debounce then
		debounce = true
		
		local explosion = Instance.new("Explosion",game.Workspace)
		explosion.Position = missile.Position

		missile:Destroy()
	end
end)

https://gyazo.com/3d1830fb80b680201a1f0006d977d53c (GIF of the nuke working)

I tested this code, the floor that it touches is anchored but the missile isn’t anchored because touched events dont work if the object that’s using the touched event is anchored. the name of the object I want it to touch is correct which is “Part” and it falls and hits the ground and explodes

the global script is located inside of the rocket

touched event is good for simple things like this but when you start messing around with more complex things involving detection you should consider using worldroot raycast (example: detecting a ledge using raycasts to climb ledges in a parkour system)

2 Likes

Why do you have a G =? What’s that supposed to do?

Also why don’t you do .Touched function for the baseplate? Something like this:

game.Workspace.Baseplate.Touched:Connect(function(hit)
if hit.Parent.Name == “Nuke” then
print(“Touched Nuke”)
end
end)

Edit: just saw this be suggested already

he has the G so he can disconnect it later on.

Also, instead of checking if the baseplate is touching it, why don’t you just detect if the nuke is touching it?

Would disconnecting it stop anymore signals to be sent through .Touched?

There’s not much of a difference but sure, since it will probably not send as many .Touched signals.

Disconnecting basically just stops the event from receiving more inputs

doing touched on the nuke is easier because then ti doesn’t have to filter through every object the nuke is touching.

1 Like

Oh ok, thanks for the elaboration! :smiley:

How is that related? OP will have to disconnect the function anyway. Or just destroy the nuke.

Check if you have both the nuke and baseplate CanTouch property true, if it doesn’t work then try to weld a part in front of the nuke and then check if the baseplate touches the part