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

How to check if a part touched a model?

So I have a cannonball, and I want to see if it touched a MODEL not a part. But I didn't know where to start, so I thought I would come here. I want it to see if the ball touches the model, and if it touched a model, then you get a point, with a debounce, of course. But I think I can take care of that. For now, can you please help me find witch model, not part, my ball touched?

3 answers

✓ Accepted answer

You have a few options here...

1 is an ugly method called magnitude, works best on circles:

if (part.Position-part2.Position).Magnitude < (whatever the size of part2 is, any axis) then
	print('in range')
end

You can loop it or whatever.

You can use region3, raycasting, .Touched, GetTouchingParts()

local part = workspace.Part
for _, v in pairs(part:GetTouchingParts()) do
	print(v.Name)
end

You can loop it again for the next time its touched

then theres the good old .Touched

part.Touched:Connect(function(obj)
	if obj:IsDescendantOf(workspace.Model) then
		print('model touched')
	end
end)

You can also do it the other way

for _, v in pairs(model:GetDescendants()) do
	v.Touched:Connect(function(obj)
		if obj == part then
			print('touched part')
		end
	end)
end

So uh, see which one helps you, gl bye

9 comments

0

bye

0

bye

0

bye

0

magnitude is a good choice for squares hitbox, get touching part is useless tbh, 3rd is just check parent and 4th is the best imo, but if you dont want to index anything then my method i guess

0

Your method is good on performance, magnitude is terrible for square hitboxes. GetTouchingParts is extremely useful, I don't know why you think it's useless, I'd find other ways, methods and other resources though. You could also apply heavy math but that's absurd

0

Wait that's not even your method, that's Frindows im talking about. Your method is absolutely useless, sorry

0

Your 3rd script was exactly what I wanted. thanks

0

I was looking for a way without a loop, and I found it. Xapelize had a good answer, but like....

0

you mean frindow? xapelizes answer was bad

It is currently not possible to detect if it is touching an entire model but instead you can insert a part into the model and resize it until it is even with the model. Then you can set CanCollide to false and set Transparency to 1.

4 comments

0

Thats actually a good idea. I didn't know though, that you couldn't find a model. One bad thing though, my model is a boat

0

with a bow and all

0

Just weld the part to the boat

0

alright

Just detect hits between parts, and detect if its in your desired model. Very simple solution:

if hit.Parent:IsA("Model") and hit.Parent.Name == "YourModel" then

3 comments

0

I thought that only worked for parts

0

it only works for baseparts, or unions, but you could detect parent

0

mate, your answer didn't work XD

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