I’m trying to spawn a hitbox around my projectile but the hitbox stays at the first position instead of constantly moving with the projectile, I’ve tried weld constraints but that also didnt work,
local plr = game.Players.LocalPlayer
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local humRP = char:WaitForChild("HumanoidRootPart")
local RS = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local debounce = false
local CD = 0
local isActive = false
local tpRemote = RS.Remotes.Teleport
local mouse = plr:GetMouse()
local KEY = Enum.KeyCode.V
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {char}
local camera = workspace.CurrentCamera
local function throwKunai()
local rayMaxDist = 1500
local mousePos = UIS:GetMouseLocation()
local rayOrigin = camera:ViewportPointToRay(mousePos.X, mousePos.Y)
local raycastResult = workspace:Raycast(rayOrigin.Origin, rayOrigin.Direction * rayMaxDist)
if raycastResult == nil then print("nil")
return
end
local kunai = RS.FX.RaijinKunai:Clone()
local kunaiPosition = humRP.Position
kunai.Parent = workspace.Map.Ignore
kunai.CanCollide = false
kunai.Anchored = true
kunai.CFrame = CFrame.lookAt(kunaiPosition, raycastResult.Position) * CFrame.Angles(0, math.rad(-90), math.rad(90))
local hitBox = Instance.new("Part")
hitBox.Parent = kunai
hitBox.Anchored = true
local distance = (raycastResult.Position - kunaiPosition).Magnitude -- (Target Position - Object Position)
local speed = 150
local tweenTime = distance / speed
local objHit = raycastResult.Instance
local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local kunaiDirection = {Position = raycastResult.Position}
local tweenKunai = TS:Create(kunai, tweenInfo, kunaiDirection)
tweenKunai:Play()
print(objHit)
print("Pressed V")
end
UIS.InputBegan:Connect(function(inp, gpe)
if gpe then return end
if inp.KeyCode == KEY and not debounce then
debounce = true
throwKunai()
task.wait(CD)
debounce = false
end
end)