How would i make my throw script have a max distance on where to throw?

I made a script that allows you to throw a door (yes ik, very cool). Now, it works. BUT, it allows you to throw the part wherever you want, i want to make it so it has to land on a part on a specific radius.
I’m guessing i have to use raycasting.
How would i implement this?

Here’s my current script:


local Tool = script.Parent
local Contents = Tool:WaitForChild("Contents")
local Events = Contents:WaitForChild("Events")

local ActionEvent = Events:WaitForChild("Action")
local ratio = 2 


ActionEvent.OnServerEvent:Connect(function(Player, Action, mousepos)

if Action == "Activated" then

print("Tool has been activated by: "..Player.Name)

local direction = (mousepos - Player.Character.PrimaryPart.Position)
	
	
	local force = direction * ratio + Vector3.new(0, game.Workspace.Gravity * 0.5 / ratio, 0)
	
	Tool.Parent = workspace
	Tool.Handle.AssemblyLinearVelocity = force
	
	

end
end)
1 Like

Do you just need to know how to clamp a point to within a radius?

2 Likes