Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make this soldier attack R15 NPCs? (Currently Works for R6 only)

http://prntscr.com/mfw5y2 http://prntscr.com/mfw70i (Image of the model and zombie used)

https://gyazo.com/54280853404624398045c5bb9a0ef954 (Soldier attacking R6 NPCs) https://gyazo.com/cb150ccb99d48adc25e943d40ccd4d80 (Solider not attacking R15 NPCs)

http://prntscr.com/mfw87g I tried editing the script a bit, for the soldier to attack the UpperTorso (R15) instead of Torso (R6)

I appreciate anyones help in advance thanks!! :))

Edit:

local CanSeeTarget = StateMachine.NewCondition() CanSeeTarget.Name = "CanSeeTarget" CanSeeTarget.Evaluate = function() local humanoids = HumanoidList:GetCurrent() local soldiers = {} local enemies = {} for _, object in pairs(humanoids) do if object and object.Parent and not game.Players:GetPlayerFromCharacter(object.Parent) and object.Health > 0 and object.WalkSpeed > 0 and object.Parent:FindFirstChild("UpperTorso") then local torso = object.Parent:FindFirstChild("UpperTorso") local distance = (soldier.Torso.Position - torso.Position).magnitude if distance <= configs["AggroRange"] then if object.Parent.Name == "Soldier" then table.insert(soldiers, object.Parent) else table.insert(enemies, object.Parent) end end end end

3 comments

0

can you include your script at least? So we know what you're doing wrong

0

local CanSeeTarget = StateMachine.NewCondition() CanSeeTarget.Name = "CanSeeTarget" CanSeeTarget.Evaluate = function() local humanoids = HumanoidList:GetCurrent() local soldiers = {} local enemies = {} for _, object in pairs(humanoids) do if object and object.Parent and not game.Players:GetPlayerFromCharacter(object.Parent) and object.Health > 0 and object.WalkSpeed > 0 and objec

0

Hello, could you please use a code block. Go back to your edits, click that Blue LUA button then paste the script inside the 2 lines. Thanks!

1 answer

Possibly the problem is that UpperTorso is R15 only, and the Torso is R6 only. The parts that are for both for R6 and R15 are the Head and the HumanoidRootPart. Mind if you try replacing UpperTorso for HumanoidRootPart?

local CanSeeTarget = StateMachine.NewCondition() 
CanSeeTarget.Name = "CanSeeTarget" 
CanSeeTarget.Evaluate = function() 
	local humanoids = HumanoidList:GetCurrent() 
	local soldiers = {} 
	local enemies = {} 
	for _, object in pairs(humanoids) do 
		if object and object.Parent and not game.Players:GetPlayerFromCharacter(object.Parent) and object.Health > 0 and object.WalkSpeed > 0 and object.Parent:FindFirstChild("HumanoidRootPart") then -- Replace in your code for HumanoidRootPart
			local torso = object.Parent:FindFirstChild("HumanoidRootPart") -- Replace in your code for HumanoidRootPart
			local distance = (soldier.Torso.Position - torso.Position).magnitude 
			if distance <= configs["AggroRange"] then 
				if object.Parent.Name == "Soldier" then 
					table.insert(soldiers, object.Parent) 
				else 
					table.insert(enemies, object.Parent)
				end
			end
		end
	end
end
	

This discussion is preserved as it was. New answers, comments, and votes are closed.