Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why will my hit detection script not detect a hit?

I have a rocket coming down from the sky. I want it to do something when it hits anything (including terrain). However, the following exert from my script script does nothing:

function onTouch(part)
	print("called")
	if ready then
		print("time for boom boom :D")
	end
end

script.Parent.Touched:connect(onTouch)

The script is not disabled or anything, it just doesn't recognize when the part touches something.

Also, IDK if this can affect it, but the part has a mesh in it.

2 comments

0

Meshes don't really work properly with the Touched event. You would need a hitbox with no mesh.

0

Oh thx I will try that

1 answer

I usually don't call functions. I call them directly so it won't be that confusing or something like that. Maybe this will fix your problem.


--local ready = true (Must be true)
--If you want to do that if it's NOT ready then do "if not ready then"(Ready must be a variable set to false).


script.Parent.Touched:connect(function(touch)
print(touch.Parent.Name) --It will print the name of the thing that the rocket touched!
if ready then --I'm assuming "ready" is an variable that's true.
print("Time for boom boom :D")
   end
end) --Don't forget the ")"
if I helped then
--Click the "Accept Answer" down bellow
else
--Comment what's wrong and I'll try to fix it
end

1 comment

0

Whaaaa? This so doesn't work. First of all, you have an extra 'end' in the above script. Also, this executes the thing right when the ready variable gets changed to true (when the rocket gets armed) and it creates an error.

This discussion is preserved as it was. New answers, comments, and votes are closed.