Unexpected error

Hello, i’m actually working in a CRPG game, the problem is when i make the NPCs, i used :WaitForChild("Torso") but the script still didn’t work, i got this error:

Torso is not a valid member of Configuration "Workspace.MobHolder.Grass Monster.Mind"

Also the explorer and script:

image

local Configuration = script.Parent.Parent.Configuration

cd = false

script.Parent.TargetHumanoid:GetPropertyChangedSignal("Value"):Connect(function()
	if script.Parent.TargetHumanoid.Value ~= nil then
		if (script.Parent.Parent:WaitForChild("Torso") - script.Parent.TargetHumanoid.Parent.Torso.Position).Magnitude <= Configuration.Distance.Value and cd == false then
			cd = true
			script.Parent.TargetHumanoid:TakeDamage(Configuration.Damage.Value)
			wait(Configuration.Cooldown.Value)
			cd = false
		else
			script.Parent.Parent.Enemy.WalkToPoint = script.Parent.TargetHumanoid.Value.Parent.HumanoidRootPart.Position
		end
	end
	wait()
end)

On this line you are accessing
script.Parent.TargetHumanoid.Parent.Torso.Position
That’s the problem.
I don’t think you meant to put TargetHumanoid in that.

2 Likes

Is ‘TargetHumanoid’ an object Value?

Try replacing this;

if (script.Parent.Parent:WaitForChild("Torso") - script.Parent.TargetHumanoid.Parent.Torso.Position).Magnitude <= Configuration.Distance.Value and cd == false then

With this;

if (script.Parent.Parent:WaitForChild("Torso") - script.Parent.TargetHumanoid.Value.Parent.Torso.Position).Magnitude <= Configuration.Distance.Value and cd == false then
2 Likes

Hello, new error:

Workspace.MobHolder.Grass Monster.Mind.AI:7: attempt to perform arithmetic (sub) on Instance and Vector3

My apologies. You can not perform arithmetic on an Instance and a Vector3, you should just add .Position to Torso as well.

if (script.Parent.Parent:WaitForChild("Torso").Position - script.Parent.TargetHumanoid.Value.Parent.Torso.Position).Magnitude <= Configuration.Distance.Value and cd == false then
1 Like

Thank you! Now i can continue with the Attack animation.