Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why will my hit detection script not detect a hit?

Asked by 6 years ago

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.

0
Meshes don't really work properly with the Touched event. You would need a hitbox with no mesh. hiimgoodpack 2009 — 6y
0
Oh thx I will try that RiskoZoSlovenska 378 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
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. RiskoZoSlovenska 378 — 6y
Ad

Answer this question