I am trying to make a script where your mouse position determines where the hitbox will be placed. I want the hitbox to be placed regardless, but differently depending on the distance from the player and the mouse. I have it to where if this said distance is lower than the max range, then it will place the hitbox just fine, but I also want the hitbox to be placed if the distance is larger than the max range. The hitbox would still try to follow the mouse’s position, but still inside the max distance. Here is some of my script.
local hrp = player.Character.HumanoidRootPart
local hitbox = game.ReplicatedStorage.Objects.Galactic.GalacticShowerHitbox:Clone()
hitbox.Parent = workspace
local area = 40 -- max distance
local dist = (pos.Position - hrp.Position).Magnitude -- distance between
if locked then
hitbox.CFrame = hrp.CFrame
elseif not locked then
if dist <= area then
hitbox.Position = pos.Position -- if in the area, place the hitbox on mouse pos
else
-- if out of the area, place the hitbox as close to mouse as possible, without going out of area.
end
end
Thanks in Advance