[HELP] Place down surface if both Mouse.Hit.Position and Projectile.Position Match

So I ran into a problem that puts the surface where the mouse’s location is, not mattering if the projectile hit that position, just if a part shares the looked Attribute. Therefore, we can try it out with some other part that has the same attribute as the baseplate: “playable”, if any part contains this attribute and the projectile touches it, it’ll detect it as a Touched and the ball will disappear but the surface will be placed where the mouse was aiming at.

Example:
f8790ed9adcbb82876e8ba6eb43f937a

Therefore I wanted to make it if both, Mouse.Position and the Projectile.Position match, then place the surface. That’s where the problem comes, both Mouse.Position and the Projectile.Position won’t always Match! (as you can see in the video the results of their positions):

So how will you be able to place down the surface exactly where you aimed at if both Positions don’t match? Please help me out, thank you!

An example of what I want to achieve; This script doesn’t actually work due to the “clone.Position == mouseHit.Position” but I put it in the script so you would be able to understand what I mean:

(Clone = Projectile)

1 Like

You could try making it to where they just barely match. Positions can vary by the thousandth so checking if they’re exactly the same might not be ideal.

-- margin of error of 1 stud. you could decrease if too much
if (mouseHit.Position - clone.Position).Magnitude <= 1 then
    -- do stuff
end
2 Likes

Thank you so much!!! This is very helpful! I didn’t know a .magnitude existed. Question, what could be a few functions or terms that you may know that come very handy to know? I hate to keep asking people for help, but when I’m stuck well… I’m stuck! :joy:

(I also look for things in Roblox’s API, but I can’t always find the exact term I need for a script, so how did you get to know about them?)

Honestly, I don’t keep them all memorized. You just learn them as you go, lol.

Magnitude is extremely important though, there are so many applications for it so make sure you remember that one. Also remember math.floor and math.ceil for rounding down or up

1 Like