Hi, I’ve been trying to make a sort of dash which has a hitbox that follows the player,. What would be the best method to make the hitbox stay in front of the player? Ive tried using part.Position = hrp.CFrame.Position but it didnt work.
You would need to constantly update the position of the hitbox, presumably every frame, however this can be performance heavy and unnecessary.
Why don’t you just parent the hitbox to the player’s character and position it 3-5 studs in front of the player? Also you should use .CFrame so it takes rotation into account.
local function createHitbox(character)
local torso = character:FindFirstChild("HumanoidRootPart")
if not torso then return end -- if no torso then dont run
local hitbox = Instance.new("Part")
hitbox.Size = Vector3.new(4, 5, 2) -- Adjust size as needed
hitbox.Transparency = 1 -- Make it invisible (set to 0 to debug)
hitbox.CanCollide = false
hitbox.Anchored = false
hitbox.Massless = true
hitbox.Name = "Hitbox"
hitbox.Parent = character
local weld = Instance.new("WeldConstraint")
weld.Part0 = torso
weld.Part1 = hitbox
weld.Parent = hitbox
end
-- Connect to CharacterAdded event
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(createHitbox)
end)
local weld = Instance.new("Weld")
weld.C0 = CFrame.new(0,0,-1) -- -1 is to be in front of the character
-- you can adjust C0 to move the hitbox around with respect to the HumanoidRootPart
-- though if it were me I would just center it on the character.
weld.C1 = CFrame.identity
weld.Part0 = hitboxpart
weld.Part1 = Char.HumanoidRootPart
weld.Parent = hitboxpart
-- note you should only do this once each time the character spawns