Here it is only dealing damage to players, but I want to damage npc too, if only npc is around me it will only damage him, if it has the player and npc will deal damage together. And the same for the player.
~LocalModuleScript Damage
local plrs = game.Players:GetPlayers() table.insert(plrs, game.Workspace.Map.Npcs.Bandit:GetChildren()) -- End dark particles for i, v in pairs(plrs) do local char = v.Character if char then if v.Name ~= player.Name and (char.HumanoidRootPart.Position - pos).magnitude <= size/2 and math.abs(char.HumanoidRootPart.Position.Y - pos.Y) <= 7 then affected[#affected + 1] = v elseif v.Name ~= player.Name and (char.HumanoidRootPart.Position - pos).magnitude <= size then lessAffected[#lessAffected + 1] = v end end end -- for i, v in pairs(affected) do local char = v.Character if char then -- damage for o = 1, 30 * speed do char.HumanoidRootPart.CFrame = char.HumanoidRootPart.CFrame - Vector3.new(0, speed/30, 0) char.Humanoid.Health = char.Humanoid.Health - (damage / (30 * speed)) wait(1/30) end end end
-- Edit/ I just remembered that too.
~Script Damage
local char = player.Character for i, v in pairs(char:GetChildren()) do if v:IsA("BasePart") then coroutine.resume(coroutine.create(function() --ModuleScript local deb = false v.Touched:Connect(function(hit) if game.Players:FindFirstChild(hit.Parent.Name) and not deb then --Script
Before you loop all the players, make a variable off of the players like this:
local players = game.Players:GetPlayers()
Then you have to add your npcs to that list of players so that they also go through the loop and can take damage:
table.insert(players, game.Workspace.Npc) -- Change with whatever your npc is named
Edit:
And don't forget of course to change your first loop:
for i, v in pairs(players) do
You can use the function of the Humanoid
which is :TakeDamage()
. It's quite simple. In the brackets you will put the amount of health that you want to reduce from the player.