Clicking to damage mobs

Currently ive got my player being teleported into a “boss arena” I want the player to damage the boss everytime they click (there is a remote event for clicking setup) So i’ve got afew issues here.

How should I detect/calculate damage and then apply to the boss?
Is it possible to only damage the boss when within a certain number of studs?

I have a general idea involving remote events but because I can’t figure out the player being within radius the boss is being attacked even when the player is not in the boss arena lol

You can figure out the distance between two objects with the Magnitude value of Vector3s:

local pos1 = workspace.Part1.Position
local pos2 = workspace.Part2.Position

local distance = (pos1 - pos2).Magnitude --distance in studs

So now you can figure out how many studs away the player is from the Boss.

You can also use this to figure out the damage applied to the boss.

For example, when you click a part on the boss - what is the distance of the mouse from the head?
Let’s say your boss is 100 studs tall.

local dist = (mouse.Hit.p - head.Position).Magnitude
local MaxDamage = 100

local Damage = MaxDamage / dist

--click feet - damage < 10
--click torso damage ~ 50-60
--click here damage 80+

Its very basic math but you can improve that as you gain experience.

For more knowledge on how to apply damage to a Player (or boss if it’s Humanoid based), look up the Roblox Developer Hub website and search for Humanoid, TakeDamage, and Mouse.

This is a perfect place for me to start, thanks!