So I’m trying to make a skill for a certain character that summons a soldier/ an army. The problem is it hits me along with everyone else. How do I make it so that it only hits the other players and not hit me?
Server Script:
local RTorso = script.Parent.HumanoidRootPart
local Humanoid = script.Parent.Humanoid
local function findtarget()
local aggro = 300
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local vtorso = v:FindFirstChild("HumanoidRootPart")
if v.Name ~= "RomanSoldier" then
if human and vtorso and v ~= script.Parent then
if (RTorso.Position - vtorso.Position).magnitude < aggro then
target = vtorso
end
end
end
end
return target
end
while wait() do
local torso = findtarget()
if torso then
Humanoid:MoveTo(torso.Position)
end
end
local RTorso = script.Parent.HumanoidRootPart
local Humanoid = script.Parent.Humanoid
local function findtarget()
local aggro = 300
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local vtorso = v:FindFirstChild("HumanoidRootPart")
if v.Name ~= "RomanSoldier" then
if human and vtorso and v ~= script.Parent then
if (RTorso.Position - vtorso.Position).magnitude < aggro then
target = vtorso
end
end
end
end
return target
end
while wait() do
local torso = findtarget()
if torso then
Humanoid:MoveTo(torso.Position)
Humanoid.MoveToFinished:Wait()
end
end
also thats not the killing script, you should not fliter the target here, if you get the model from toolbox you should find the kill script in it
It could probably because some parts have .CanCollide enabled.
You can disable this in the propities tab any part.
And in-game you can do this by simply doing part.CanCollide = false.
Hope that helps!
PD: Check what @NarakuLite said! That can probably help you fix some thigns inside your script. I just answered your question, not fixed your code
I can’t give you a script, but I can tell you exactly what you’ll need to do in order for the NPCs to recognize the difference between players and other NPCs.
You’ll need to use CollectionService and add one tag for all the players, and a different tag for all the NPCs. (i.e players would have the “friends” tag, and NPCs would have the “enemies” tag.
You can read more in depth in the article for CollectionService on the DevHub.
You can simply add a value inside the NPC like “creator” with the player’s name. Then have the attack script check if the target’s name is the creator’s name, if not it’ll damage. No need to do all of this.
how does the script know when to fire? is there a button that is detected on the client side and fires a remote event so the server script knows when to run?
Well there technically isn’t a script/button to make the script run because the script already runs when the soldiers spawn in. But there is a script to make the soldiers spawn in since I keep them in replicated storage.