Hey Everyone, this is my first topic. 
Currently i’m trying to put together my first game, learning on my own, but mostly from you awesome people here on the forum. So i want to say thank you for all the help i have gotten so far and in the future. MUCH appreciated!
Now though, I need help figuring out why my script isn’t working fully. I’m not really sure if it is the code itself or the way i am designing the system in play.
What i’m trying to do is make an enemy NPC damage both the player and an object that the player deploys into workspace from their backpack. Basically everything is working with the npc finding its targets and hitting the player making their player health go down but for some reason when the npc touches a part i named “torso” of the model that’s deployed into workspace (which has a humanoidpart in it) the health of that model is not affected by the npc’s touch.
I have tested: Starting with that deploy-able object in the workspace instead of being deployed into workspace mid game and the objects health gets hit and goes down on the npc touch…
So this is where i’m confused, is it because the npc script is not recognizing the humanoid object because it came in after the fact??? Is this a client-server issue??
Also to note: I started with that evil peppa in the toolbox so i could understand the basics of how an npc works and i cut the script down and rebuilt it back up to work for me. Then once i had it working for my player i wrote in the code where it can look at both the player and location of the deployed object…
Here is my rebuilt part in question…
Press to open code
function GetTorso(part)
local chars = game.Workspace:GetChildren()
local torso = nil
for _, v in pairs(chars) do
if v:IsA'Model' and v ~= script.Parent and v.Name == GetPlayerNames() then
local charRoot = v:FindFirstChild'HumanoidRootPart'
if (charRoot.Position - part).magnitude < SearchDistance then
torso = charRoot
end
end
end
return torso
end
function GetTowerTorso(part)
local Arena = game.Workspace:WaitForChild("Arena")
local TowerLocation = Arena.SetLoc
local towertorso = nil
if TowerLocation.Value.magnitude < SearchDistance then
towertorso = TowerLocation.Value
end
return towertorso
end
------------------------------=========================Damage=========================--------------------------------------------
for _, bugparts in pairs(ai:GetChildren()) do
if bugparts:IsA'Part' then
bugparts.Touched:connect(function(p)
if p.Parent.Name == GetPlayerNames() and p.Parent.Name ~= ai.Name then
local enemy = p.Parent
local enemyhuman = getHumanoid(enemy)
enemyhuman:TakeDamage(aiDamage)
end
end)
end
end
for _, bugparts in pairs(ai:GetChildren()) do
if bugparts:IsA'Part' then
bugparts.Touched:connect(function(p)
if p.Name == "torso" then
local enemy = p.Parent
local enemyhuman = getHumanoid(enemy)
enemyhuman:TakeDamage(aiDamage)
end
end)
end
end
--------------------------------------------------------------------------------------------------------------------------------------
This is a brake down of the backpack part i want to deploy and take damage…
(ps. I’m open to criticism) thanks again.
