Create a Hitbox that follows player

so i wasa tyring to make a hitbox whereby it follows the player for a set amount of seconds then destroys however if it touches a player the hitbox destroys itself, currently I’m having trouble moving the hitbox with the player

local rs = game:GetService("ReplicatedStorage")
local stevent = rs:WaitForChild("SkillsEvent").STEvent


stevent.OnServerEvent:Connect(function(plr)
	local chr = plr.Character
	chr:SetAttribute("IsAttacking", true)
	local hrp = chr.PrimaryPart
	local rootpart = chr.PrimaryPart
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(math.huge, 0, math.huge)
	bv.Velocity = rootpart.CFrame.LookVector * 50
	bv.Parent = rootpart
	local Watertrial = rs:WaitForChild("Modules").WeaponHander.WaterTrail
	local ListOfWeapons = {
		"BasicSword",
		"RengokuSword",
		"PlaceHolder1",
	}
	
	for i,v in chr:GetChildren() do
		if v:IsA("MeshPart") and table.find(ListOfWeapons, v.Name) then
			for i,s in Watertrial:GetChildren() do
				local ClonedPart = s:Clone()
				ClonedPart.Parent = v
				ClonedPart.Attachment0 = v.Attachment1
				ClonedPart.Attachment1 = v.Attachment2
			end
		end
	end
	
	local hitboxCFrame = chr.HumanoidRootPart.CFrame
	local hitboxSize = Vector3.new(10,5,20)
	local damage = 18
	local hitbox = rs.Hitbox2:Clone()
	hitbox.Parent = workspace
	hitbox.CFrame = hitboxCFrame
	hitbox.Size = Vector3.new(hitboxSize, hitboxSize, hitboxSize)
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = hitbox
	weld.Part1 = plr.Character:WaitForChild("Torso")
	weld.Parent = hitbox
	local hitcontent = workspace:GetPartBoundsInBox(hitboxCFrame, hitboxSize)
	local hitlist = {}
	for _,v in pairs(hitcontent) do
		if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= chr and not table.find(hitlist, v.Parent) then
			table.insert(hitlist, v.Parent)
			v.Parent.Humanoid:TakeDamage(damage)
		end
	end

	task.wait(1)
	for i,v in chr:GetChildren() do
		if v:IsA("MeshPart") and table.find(ListOfWeapons, v.Name) then
			v.Trail:Destroy()
		end
	end
	bv:Destroy()
	chr:SetAttribute("IsAttacking", false)

	
end)


If you want the hitbox to follow a player, AlignPositions and Align Orientation would be the recommended way to go. I’m having a hard time understanding what exactly this method is supposed to do. It creates the hitbox, but it does the spatial query instantly, negating the use for a hitbox in the first place. Do you want it to continuously detect collisions? .Touched events would be the way to go for a simple hit detection system, especially when you don’t have instances moving at high speeds.

Weld the hitbox to the HumanoidRootPart of the player if you want the hitbox to be always directly on the player / same place on the player. If you mean slightly less responsive / not instant full weld then yea try what the person above me said ^, align positions/orientation,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.