I want to make a pan,that wouldn’t deal ANY damage to people,but only to other NPC’s(I need it, to use on different bosses).
Here’s the script:
task.wait(1)
local tool = script.Parent
local sss = game:GetService("ServerScriptService")
local modules = sss:WaitForChild("Modules")
local attackmod = require(modules:WaitForChild("Attack"))
local abilityEvent = tool:FindFirstChild("Ability")
local sound = tool:FindFirstChild("Script"):WaitForChild("Sound")
local humanoid = tool.Parent:FindFirstChild("Humanoid")
local character
local attackAnim
local attackData = {
Damage = 15,
StartUp = 0.2,
Knockback = Vector2.new(30,20),
Stun = 2,
Linger = 0.4,
Sound = "Bonk"
}
local cooldown = 1
local debounce = false
local abilityDebounce = false
local abilityCooldown = 7
local toolDebounce = false
local function onActivated()
if toolDebounce then return end
toolDebounce = true
attackAnim:Play()
attackmod.Start(character, tool, attackData)
task.wait(1)
toolDebounce = false
end
local function onAbility(newChar)
if newChar.Name == character.Name then
if abilityDebounce then return end
abilityDebounce = true
sound:Play()
wait(1.4)
humanoid.WalkSpeed = 34
wait(0.1)
humanoid.WalkSpeed = 33
wait(0.1)
humanoid.WalkSpeed = 31
wait(0.1)
humanoid.WalkSpeed = 30
wait(0.1)
humanoid.WalkSpeed = 28
wait(0.1)
humanoid.WalkSpeed = 27
wait(0.1)
humanoid.WalkSpeed = 25
wait(0.1)
humanoid.WalkSpeed = 24
wait(0.1)
humanoid.WalkSpeed = 22
wait(0.1)
humanoid.WalkSpeed = 21
wait(0.1)
humanoid.WalkSpeed = 20
wait(0.1)
humanoid.WalkSpeed = 19
wait(0.1)
humanoid.WalkSpeed = 18
wait(0.1)
humanoid.WalkSpeed = 17
wait(0.1)
humanoid.WalkSpeed = 16
wait(0.1)
abilityDebounce = false
wait(abilityCooldown)
end
end
local function onTouched(hit)
if debounce then return end
local model = hit:FindFirstAncestorOfClass("Model")
if model and model ~= character and not model:FindFirstChild("PlayerHit") then
if model.Values:FindFirstChild("BasicCounter") then require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("CounterMoves")).BasicCounter(character,model,tool.Activated) return end
local humanoid = model:FindFirstChildWhichIsA("Humanoid")
if humanoid then
debounce = true
if game.Players:GetPlayerFromCharacter(model) then
local ePlr = game.Players:GetPlayerFromCharacter(model)
if ePlr.equipped.Value == 9 then
return
end
end
task.wait(1)
debounce = false
end
end
end
tool.Equipped:Once(function()
character = tool.Parent
attackAnim = character.Humanoid.Animator:LoadAnimation(script.Attack)
end)
tool.Activated:Connect(onActivated)
tool.Hitbox.Touched:Connect(onTouched)
abilityEvent.OnServerEvent:Connect(onAbility)
Put player’s character model inside () and if it actually exists, then you can return I guess
You can put any model inside, if it is not a player it should give nil
To make your gear only deal damage to NPCs and not to players, you can modify the onTouched function to check if the hit object is a player or an NPC. Here’s an updated version of your script with the necessary changes.
task.wait(1)
local tool = script.Parent
local sss = game:GetService("ServerScriptService")
local modules = sss:WaitForChild("Modules")
local attackmod = require(modules:WaitForChild("Attack"))
local abilityEvent = tool:FindFirstChild("Ability")
local sound = tool:FindFirstChild("Script"):WaitForChild("Sound")
local humanoid = tool.Parent:FindFirstChild("Humanoid")
local character
local attackAnim
local attackData = {
Damage = 15,
StartUp = 0.2,
Knockback = Vector2.new(30,20),
Stun = 2,
Linger = 0.4,
Sound = "Bonk"
}
local cooldown = 1
local debounce = false
local abilityDebounce = false
local abilityCooldown = 7
local toolDebounce = false
local function onActivated()
if toolDebounce then return end
toolDebounce = true
attackAnim:Play()
attackmod.Start(character, tool, attackData)
task.wait(1)
toolDebounce = false
end
local function onAbility(newChar)
if newChar.Name == character.Name and not abilityDebounce then
abilityDebounce = true
sound:Play()
wait(1.4)
for speed = 34, 16, -1 do -- I did this with a cycle
humanoid.WalkSpeed = speed
wait(0.1)
end
abilityDebounce = false
wait(abilityCooldown)
end
end
local function onTouched(hit)
if debounce then return end
local model = hit:FindFirstAncestorOfClass("Model")
if model and model ~= character and not model:FindFirstChild("PlayerHit") then
if model.Values:FindFirstChild("BasicCounter") then
require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("CounterMoves")).BasicCounter(character, model, tool.Activated)
return
end
local humanoid = model:FindFirstChildWhichIsA("Humanoid")
if humanoid and not game.Players:GetPlayerFromCharacter(model) then -- If no player then do things
debounce = true
attackmod.Start(character, tool, attackData)
task.wait(1)
debounce = false
end
end
end
tool.Equipped:Once(function()
character = tool.Parent
attackAnim = character.Humanoid.Animator:LoadAnimation(script.Attack)
end)
tool.Activated:Connect(onActivated)
tool.Hitbox.Touched:Connect(onTouched)
abilityEvent.OnServerEvent:Connect(onAbility)
I didn’t change your code much so everything should work as it did before…
You can use CollectionService to add a tag to every NPC, then when you hit someone, check if the NPC has the tag, and if yes, deal damage, you can put all your NPCs in a folder and do something like this.
local CollectionService = game:GetService("CollectionService")
local Folder = script.Parent -- Your Folder
for i,v in Folder:GetChildren() do
if v:FindFirstChild("Humanoid") then
CollectionService:AddTag(v, "IsNPC")
end
end
-- Rest of your code here.
EDIT: Also your script is just a mess, use a for loop for the humanoid walk speed part,
for i = 35, 16, -1 do
humanoid.Walkspeed = humanoid.Walkspeed -1
task.wait(0.1)
end
I mean, a Folder just so you can keep it organised, you can also do it in a table, but I would prefer in a Folder. The script will loop through the folder and assign a tag to that NPC. If it’s not in that folder it won’t assign. Put all your NPCs in a Folder and put that script in there. Then use CollectionService:HasTag() to check if the NPC has the tag, and if it does deal damage.