Im trying to make a part spawn in multiple times in order to make a barrage move, i made it so it spawns in the player and reaches forward, but when trying to make it deal damage, the touch doesnt register.
I tried multiple things, made sure cantouch is true, but it only detected the touch when i disabled massless and moved around sporadically near a dummy, and only sometimes.
How can i make the part register a humanoid has touched it?
while attack do
character.Humanoid.WalkSpeed = 3
local newhitbox = Instance.new("Part")
newhitbox.Name = "hitbox"
newhitbox.CFrame = character.HumanoidRootPart.CFrame
newhitbox.Anchored = false
newhitbox.CanTouch = true
newhitbox.CanCollide = false
newhitbox.CanQuery = true
newhitbox.Transparency = 0.55
newhitbox.Color = Color3.new(1, 0, 0)
newhitbox.Parent = character
newhitbox.Size = Vector3.new(4.2,5,6.69)
local w = Instance.new("Weld",newhitbox)
w.Part0 = newhitbox
w.Part1 = character.HumanoidRootPart
w.C1 = CFrame.new(0,0,-2.89)
game.Debris:AddItem(newhitbox,2)
wait(2)
newhitbox.Touched:Connect(function()
print("touched")
end)
end
this is my first post, so i hope the formatting works.
That didn’t really solve my problem, as it doesn’t fix the fact that the box that should detect any touching humanoid doesnt do that unless it has mass, which is a problem as the player twitches everytime and freezes whenever it is called. The part itself is staying on the proper place.
After reading that i tried making the touched function a regular function and call it whenever the hitbox is touched, while the box duration and spawn time is different (lasts 1 second, spawns every 0.5 second) its registering the touch, but with the spawn rate like that, its registering way too often and results in massive damage. How can i maybe add a delay to the hitbox?
while attack do
function hitbarrage(hit)
print(hit.Name.."touched")
if hit and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(1)
end
end
character.Humanoid.WalkSpeed = 3
wait()
local newhitbox = Instance.new("Part")
newhitbox.Name = "hitbox"
newhitbox.CFrame = character.HumanoidRootPart.CFrame
newhitbox.Anchored = false
newhitbox.CanTouch = true
newhitbox.CanCollide = false
newhitbox.Transparency = 0.55
newhitbox.Massless = true
newhitbox.Color = Color3.new(1, 0, 0)
newhitbox.Size = Vector3.new(4.2, 5, 6.69)
newhitbox.Parent = character
local w = Instance.new("Weld",newhitbox)
w.Part0 = newhitbox
w.Part1 = character.HumanoidRootPart
w.C1 = CFrame.new(0,0,-2.89)
game.Debris:AddItem(newhitbox,1)
wait(0.5)
newhitbox.Touched:Connect(hitbarrage)
end