I wanted to make it so the part could follow the mouse in every direction, even upwards but only within certain distance
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humrp = char:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspace
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char, part}
params.FilterType = Enum.RaycastFilterType.Blacklist
RunService.Heartbeat:Connect(function(delta)
local mouse = UIS:GetMouseLocation()
local ray = camera:ViewportPointToRay(mouse.X,mouse.Y)
local result = workspace:Raycast(ray.Origin,ray.Direction * 50, params)
if result then
part.CFrame = CFrame.new(result.Position)
else
print("not detected")
end
end)