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)