I assume you want the relative position to be the same should be something like this
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local localOffset = CFrame.new(0, 0, -5)
UIS.InputBegan:Connect(function(input, gp)
if gp or input.UserInputType ~= Enum.UserInputType.MouseButton1 then
return
end
local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
local HitBoxpart = Instance.new("Part")
HitBoxpart.Size = Vector3.new(8, 3, 8)
HitBoxpart.Anchored = true
HitBoxpart.CanCollide = false
HitBoxpart.Transparency = 0.5
HitBoxpart.Parent = workspace
local start = tick()
local c
c = RunService.RenderStepped:Connect(function()
if tick() - start > 3 then
c:Disconnect()
HitBoxpart:Destroy()
return
end
local lin = hrp.AssemblyLinearVelocity
local ang = hrp.AssemblyAngularVelocity
local predictedPos = hrp.Position + lin * game.Stats.FrameTime
local mag = ang.Magnitude
local rotDelta = CFrame.fromAxisAngle(ang.Unit, mag * game.Stats.FrameTime)
local base = hrp.CFrame - hrp.Position
local predictedCF = CFrame.new(predictedPos) * rotDelta * base
HitBoxpart.CFrame = predictedCF * localOffset
end)
end)