✓ Accepted answer
Well, in this case for iv loop is the best, so the script I made here, you will not need to make new scripts, just get an npc and put it in the enemies folder, it will automatically take damage if the sword touches the npc. Btw this script should be in the tool and im assuming you have a part named Blade.
local enemies = game.Workspace.Enemies:GetChildren()
for i, v in pairs(enemies) do
if v:IsA("Model") then
if v:FindFirstChild("Humanoid") then
wait(1)
v.HumanoidRootPart.Touched:Connect(function()
v.Humanoid:TakeDamage(10)
wait(1)
end)
end
end
end
OR you can use this one that only will damage when you click with the tool!
local enemies = game.Workspace.Enemies:GetChildren()
for i, v in pairs(enemies) do
if v:IsA("Model") then
if v:FindFirstChild("Humanoid") then
wait(1)
v.HumanoidRootPart.Touched:Connect(function()
script.Parent.Activated:Connect(function()
v.Humanoid:TakeDamage(10)
wait(1)
end)
end)
end
end
end
5 comments
for game.Workspace.Enemies.Dark4.Zombie.Health - 100 you did this - instead of this =
that was just a test, I am wanting to take like 20 health off of it
It's not your sword script, it's a random person's sword script. We don't help with free code.
but it is mine? Line 2 and 3 are theirs the rest is mine
Line 2 is a blank line and it wouldn't make sense for 3 to be made by you but the rest not because on line 5 it does something which supports the functionality line 3 gives.