I have 2 melee weapons that use part.Touched to do damage. It does work but it doesn’t work when the weapon is already touching the player’s hitbox before I press attack. Is there a way/alternative to get around this issue? I’ve been searching on forums but couldn’t find one.
The script for the weapon is;
local tool = script.Parent
local handle = tool.Handle
local debounce = false
local activated = false
local debounce2 = false
local anim2 = handle.Animation2
tool.Activated:Connect(function()
if debounce then return end
debounce = true
activated = true
handle["Cylinder.001"].saber_swing1:Play()
handle["Cylinder.001"].Trail.Enabled = true
local animation = tool.Parent:FindFirstChild("Humanoid"):LoadAnimation(anim2)
animation:Play()
task.wait(0.4)
handle["Cylinder.001"].Trail.Enabled = false
task.wait(0.3)
activated = false
debounce = false
end)
tool.Handle["Cylinder.001"].Touched:Connect(function(hit)
if activated and not debounce2 then
debounce2 = true
if hit.Parent:FindFirstChild("Humanoid") and hit.Name == "Hitbox" and hit:GetAttribute("IsAHitbox") then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(30)
tool.Handle["Cylinder.001"]["Beat Saber Hit Sound (Short left)"]:Play()
end
task.wait(0.69)
debounce2 = false
end
end)
This script is for the saber, the other melee has the same script with different directories and different damage values.