so im trying to make a humanoid take damage until touch end how ever the TouchEnded triggers while the player is still inside the part, im using a mesh part as hitbox tbh i don’t know why its doing that, tried using a repeat event since it semmed more fit to this context but don’t really know how to put the until in form since repeat unit Part.TouchEnded shouldn’t distinguish what part triggered the event so i made this, also i’dd like it being able to damage everyone in the hitbox
Hitbox.Touched:Connect(function(hit)
if hit:IsA("Part") and hit.Name == "HumanoidRootPart" and hit ~= player.Character.HumanoidRootPart then
local humanoid = hit.Parent.Humanoid
humanoid:TakeDamage(10)
table.insert(HitTable, hit)
end
end)
```
Touched event has always been a bit wonky as it only works if you keep moving inside the touch part so I recommend you do something like this instead:
local workspace = game:GetService"Workspace"
local hitBox = -- Where the HitBox is located
local debounce = {}
local wrap = coroutine.wrap
local connection -- Disconnect this connection if you want the loop to stop running
connection = game:GetService"RunService".PostSimulation:Connect(function()
for _, basePart in workspace:GetPartsInPart(hitBox) do
if not basePart.Parent then continue end
local humanoid = basePart.Parent:FindFirstChildWhichIsA"Humanoid"
if humanoid and not debounce[humanoid] then
wrap(function()
debounce[humanoid] = true
humanoid:TakeDamage(10)
task.wait() -- Enter desired wait duration here
debounce[humanoid] = nil
end)()
end
end
end)