I have created a script that clones a part called "Damager" onto a hitbox. Damager should damage everything it touches, however for some reason it is not dealing damage when it is cloned. This is the script in damager:
function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
human.Health = human.Health - 2 -- Change the amount to change the damage.
end
end
script.Parent.Touched:connect(onTouched)
It should work. This next script is the script that makes the attack work:
local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=4752814788"
mouse.KeyDown:connect(function(key)
if key == "e" then
if script.Cooldown.Value == false then
script.Cooldown.Value = true
local playAnim = humanoid:LoadAnimation(anim)
playAnim:Play()
local Damage1 = workspace.Clonables.Damager:Clone()
Damage1.Parent = workspace
Damage1.Position = player.Character.Hitbox1.Position
Damage1.Orientation = player.Character.Hitbox1.Orientation
local weld1 = Instance.new("WeldConstraint")
weld1.Parent = Damage1
weld1.Enabled = true
weld1.Part0 = Damage1
weld1.Part1 = player.Character.Hitbox1
local Damage2 = workspace.Clonables.Damager:Clone()
Damage2.Parent = workspace
Damage2.Position = player.Character.Hitbox2.Position
Damage2.Orientation = player.Character.Hitbox2.Orientation
local weld2 = Instance.new("WeldConstraint")
weld2.Parent = Damage2
weld2.Enabled = true
weld2.Part0 = Damage2
weld2.Part1 = player.Character.Hitbox2
wait (0.4)
script.Cooldown.Value = false
weld1:Destroy()
weld2:Destroy()
Damage1:Destroy()
Damage2:Destroy()
end
end
end)
In theory, all of this should work perfectly, but for some reason it is not dealing damage. Does anyone know why? Please help.

1 comment
I think the problem is at line 12, don’t think keyboard input doesn’t work like that.