CTFU aka soldier AI is work but not moving from their position / doesn't move

I making a game called “The Cat Lab” with SystemWorkGame

I make soldier AI which called CTFU

So, I put the script inside CTFU called logic AI. (I take the script from Yellow Mustang and edited.)
It seems work, but later. It doesn’t work, now…

When I click to run / Test Play / Play, CTFU seems to work, but I noticed. CTFU can’t move and when to see their enemies, CTFU also can’t shoot. (Not CTFU only, all my AI unit can’t move.)

Well, I try to find what is broken.
So, I decided to check the output and see.
https://gyazo.com/9c8954adc7e326cb47843d7787367fc8
It said, “Position is not a valid member of Model”.
Full Script: (not full actually)
https://gyazo.com/e1c6c9ee244236ab406b92a45a3a62b9
When I clicked error, it brings me to this:
https://gyazo.com/b21fb48862cfde62a5ad64448e7e2d4a
I don’t know why,
So I ask SystemWorkGame if he had a solution for fixing this.
But he said no.
So I decided to fix it by myself.
I fix by joining the game (on Roblox studio)
and check my character.
And I see.
https://gyazo.com/26b52c2818cfbf092ceec841c08138de
It linked to parent called (player.username) (i mean my username)
I seem like it’s weird.

I hope someone can fix this.

1 Like

the “Position is not a valid member of model” is caused by trying to index position on a model, you would need to do

model.PrimaryPart.Position = --position
1 Like

@Lodok3YT Alright, I will try that.

@Lodok3YT, before I test. Should I put a variable for the model? or using local model = v: FindFirstChild(“Model”),

go to that line and tell me the line

@Lodok3YT https://gyazo.com/f4e6001f61267ac5bf5219f1caf9329b

can you find where mytorso and torso are defined?

@Lodok3YT torso (CTFU): https://gyazo.com/d91bf15ba216cf521f798f4a04e92ef4 | torso (target): https://gyazo.com/5ed85f6bcbb3222e44072c2b9c696da6

um can you do print(myTorso, torso ) on the line before

@Lodok3YT, it print https://gyazo.com/6cb547d580e4bc7fb2d8097def83ad2c aka “Torso”, not print target torso, it’s called from https://gyazo.com/7ad34895d8c90cbe4c933c6901b19f98 and https://gyazo.com/97471864c53c5c6dbeee2fd3e8d6e4db?token=b4692046597029f8fec9a914969a65aa

@Lodok3YT i hate this https://gyazo.com/2fe4ae82c3ff2f1987777de860f7b33e

Can you just send the entire script so I can see what the problem with it is, also send the hierarchy explorer views for the CTFU.

Full Script:
–Body variables
local myHuman = script.Parent:WaitForChild(“Humanoid”)
local myTorso = script.Parent:WaitForChild(“Torso”)
local myHead = script.Parent:WaitForChild(“Head”)
local neck = myTorso:WaitForChild(“Neck”)
local headWeld = myTorso:WaitForChild(“Head Weld”)
local rArm = script.Parent:WaitForChild(“Right Arm”)
local lArm = script.Parent:WaitForChild(“Left Arm”)
local lShoulder = myTorso:WaitForChild(“Left Shoulder”)
local rShoulder = myTorso:WaitForChild(“Right Shoulder”)
local lArmWeld = myTorso:WaitForChild(“Left Arm Weld”)
local rArmWeld = myTorso:WaitForChild(“Right Arm Weld”)
local myTeam = script.Parent:WaitForChild(“Team”)

–M4 Variables
local m4 = script.Parent:WaitForChild(“M4”)
local m4Weld = m4:WaitForChild(“M4 Weld”)
local barrel = script.Parent:WaitForChild(“Barrel”)
local aimer = script.Parent:WaitForChild(“Aimer”)
local aimerWeld = aimer:WaitForChild(“Aimer Weld”)

–Sounds
local equipSound = m4:WaitForChild(“Equip”)
local fireSound = m4:WaitForChild(“Fire”)
local reloadSound = m4:WaitForChild(“Reload”)
local hurtSound = myHead:WaitForChild(“Hurt”)

local reloading = false
local weaponAimed = false
local weaponCool = true
local m4Equipped = false

local fullMag = 30
local mag = fullMag

local allies = {script.Parent.Name,“rifqizahin”,“jackclay1234”,“SystemWorkGame”,“ROBLOX”,“Jordan12345112”,“pokem53”,“Dummy”,“AU”,“Scientist”,“CTFU”,“”,“Commander”}
local potentialTargets = {}

local clone = script.Parent:Clone()

function checkDist(part1,part2)
return (part1.Position - part2.Position).Magnitude
end

function checkSight(target)
local ray = Ray.new(myTorso.Position, (target.Position - myTorso.Position).Unit * 100)
local part,position = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
if part then
if part:IsDescendantOf(target.Parent) then
return true
end
end
return false
end

function findTarget()
local dist = 250
local target = nil
potentialTargets = {}
local seeTargets = {}
for _,v in ipairs(workspace:GetChildren()) do
local human = v:FindFirstChild(“Humanoid”)
local torso = v:FindFirstChild(“Torso”) or v:FindFirstChild(“HumanoidRootPart”)
local team = v:FindFirstChild(“Team”)
if human and torso and v.Name ~= script.Parent.Name then
if (myTorso.Position - torso.Position).magnitude < dist and human.Health > 0 then
for i,x in ipairs(allies) do
if x == v.Name then
break
elseif i == #allies then
table.insert(potentialTargets,torso)
if team then
if team.Value ~= myTeam.Value then
dist = checkDist(torso)
target = torso
end
end
end
end
end
end
end
if #potentialTargets > 0 then
for i,v in ipairs(potentialTargets) do
if checkSight(v) then
table.insert(seeTargets,v)
end
end
if #seeTargets > 0 then
for i,v in ipairs(seeTargets) do
if (myTorso.Position - v.Position).magnitude < dist then
target = v
dist = (myTorso.Position - v.Position).magnitude
end
end
else
for i,v in ipairs(potentialTargets) do
if (myTorso.Position - v.Position).magnitude < dist then
target = v
dist = (myTorso.Position - v.Position).magnitude
end
end
end
end
return target
end

function pathToLocation(target)
local path = game:GetService(“PathfindingService”):CreatePath()
path:ComputeAsync(myTorso.Position, target.Position)
local waypoints = path:GetWaypoints()

for _,waypoint in ipairs(waypoints) do
	if waypoint.Action == Enum.PathWaypointAction.Jump then
		myHuman.Jump = true
	end
	myHuman:MoveTo(waypoint.Position)
	delay(0.5,function()
		if myHuman.WalkToPoint.Y > myTorso.Position.Y then
			myHuman.Jump = true
		end
	end)
	local moveSuccess = myHuman.MoveToFinished:Wait()
	if not moveSuccess or checkSight(target) then
		break
	end
end

end

function walkRandom()
local randX = math.random(-75,75)
local randZ = math.random(-75,75)
local goal = myTorso.Position + Vector3.new(randX, 0, randZ)
local path = game:GetService(“PathfindingService”):CreatePath()
path:ComputeAsync(myTorso.Position, goal)
local waypoints = path:GetWaypoints()

if path.Status == Enum.PathStatus.Success then
	for i,waypoint in ipairs(waypoints) do
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			myHuman.Jump = true
		end
		myHuman:MoveTo(waypoint.Position)
		delay(0.5,function()
			if myHuman.WalkToPoint.Y > myTorso.Position.Y then
				myHuman.Jump = true
			end
		end)
		local moveSucess = myHuman.MoveToFinished:Wait()
		if not moveSucess then
			break
		end
		if i % 5 == 0 then
			if findTarget() then
				break
			end
		end
	end
else
	wait(2)
end

end

function drawM4()
if m4Equipped == false then
m4Equipped = true
equipSound:Play()

	--Right Arm Setup
	rShoulder.Part1 = nil
	rArm.CFrame = aimer.CFrame* CFrame.new(1.25,0.05,-0.65) * CFrame.Angles(math.rad(80),math.rad(0),math.rad(-10))
	rArmWeld.Part1 = rArm
	
	--Left Arm Setup 
	lShoulder.Part1 = nil
	lArm.CFrame = aimer.CFrame * CFrame.new(-0.35,0.05,-1.48) * CFrame.Angles(math.rad(84),math.rad(-3),math.rad(28))
	lArmWeld.Part1 = lArm
	
	--M4 Setup
	m4Weld.Part0 = nil
	m4.CFrame = aimer.CFrame * CFrame.new(0.65,0.37,-2.22) * CFrame.Angles(math.rad(-90),0,0)
	m4Weld.Part0 = aimer
end

end

function yieldM4()
if weaponAimed == true then
weaponAimed = false
resetHead()
end
if m4Equipped == true then
m4Equipped = false
equipSound:Play()

	--Right ARm setup
	rArmWeld.Part1 = nil
	rShoulder.Part1 = rArm
	
	--Left Arm Setup
	lArmWeld.Part1 = nil
	lShoulder.Part1 = lArm
	
	--M4 Setup
	m4Weld.Part0 = nil
	m4.CFrame = myTorso.CFrame * CFrame.new(0,0,0.6) * CFrame.Angles(math.rad(-90),math.rad(-60),math.rad(90))
	m4Weld.Part0 = myTorso
end

end

function aim(target)
if weaponAimed == false then
neck.C0 = neck.C0 * CFrame.Angles(0,math.rad(-15),0)
end
weaponAimed = true
for i=0,1,0.1 do
wait()
local look = Vector3.new(target.Position.X,myTorso.Position.Y,target.Position.Z)
myTorso.CFrame = myTorso.CFrame:Lerp(CFrame.new(myTorso.Position,look),i)
if reloading == false then
aimerWeld.Part1 = nil
aimer.CFrame = aimer.CFrame:Lerp(CFrame.new(aimer.Position,target.Position),i)
aimerWeld.Part1 = aimer
end
end
end

function resetHead()
neck.C0 = neck.C0 * CFrame.Angles(0,math.rad(15),0)
end

function shoot(target)
if weaponCool == true and reloading == false then
weaponCool = false

	local shot
	if checkDist(target,myTorso) > 20 then
		shot = math.random(1,2)
		
	else
		shot = math.random(3,5)
	end
	for i = 1, shot do
		wait(0.1)
		mag = mag - 1 
	
		local flash = Instance.new("PointLight",barrel)
		flash.Brightness = 75
		game:GetService("Debris"):AddItem(flash,0.1)
		
		local bullet = Instance.new("Part",workspace)
		bullet.Size = Vector3.new(0.1,0.1,0.3)
		bullet.BrickColor = BrickColor.new("Gold")
		bullet.Material = Enum.Material.Neon
		bullet.CFrame = barrel.CFrame
		bullet.CanCollide = false
		bullet.Touched:Connect(function(obj)
			if not obj:IsDescendantOf(script.Parent) then 
				local human = obj.Parent:FindFirstChild("Humanoid")
				if human then
					if obj.Name == "Head" then
						human:TakeDamage(math.random(35,100))
					else
						human:TakeDamage(math.random(7,25))
					end
				end
				bullet:Destroy()
			end
		end)
		fireSound:Play()
		
		local spread = Vector3.new(math.random(-shot,shot)/100,math.random(-shot,shot)/100,math.random(-shot,shot)/100)
		
		local bv = Instance.new("BodyVelocity",bullet)
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		bv.Velocity = (aimer.CFrame.LookVector + spread) * 300
		
		local s = Instance.new("Sound",bullet)
		s.Volume = 0.7
		s.PlaybackSpeed = 7
		s.Looped = true
		s.SoundId = "rbxasset://sounds/Rocket whoosh 01.wav"
		s:Play()
		
		local a1 = Instance.new("Attachment",bullet)
		a1.Position = Vector3.new(0,0.05,0)
		local a2 = Instance.new("Attachment",bullet)
		a2.Position = Vector3.new(0,-0.05,0)
		
		local t = Instance.new("Trail",bullet)
		t.Attachment0 = a1
		t.Attachment1 = a2
		t.Color = ColorSequence.new(bullet.Color)
		t.WidthScale = NumberSequence.new(0.1,0.01)
		t.Lifetime = 0.3
		
		aimerWeld.Part1 = nil
		aimer.CFrame = aimer.CFrame * CFrame.Angles(math.rad(math.random(1,4)/4),0,0)
		aimerWeld.Part1 = aimer
		
		game:GetService("Debris"):AddItem(bullet, 5)
	end
	
	if mag <= 0 then
		reload()
	end
	
	delay(1, function()
		weaponCool = true
	end)
end

end

function reload()
if weaponAimed == true then
resetHead()
weaponAimed = false
end
reloadSound:Play()
reloading = true
for i = 0,1,0.1 do
aimerWeld.Part1 = nil
aimer.CFrame = myTorso.CFrame * CFrame.new(0,0.5,0) * CFrame.Angles(math.rad(-35),0,0)
aimerWeld.Part1 = aimer
if weaponAimed == true then
break
end
end
wait(4)
reloading = false
mag = fullMag
end

function main()
local target = findTarget()
if target then
if checkSight(target) then
if checkDist(myTorso,target) > 20 then
drawM4()
aim(target)
shoot(target)
end
else
if weaponAimed == true then
weaponAimed = false
resetHead()
spawn(function()
for i=0,1,0.1 do
wait()
aimerWeld.Part1 = nil
aimer.CFrame = myTorso.CFrame * CFrame.new(0,0.5,0) * CFrame.Angles(math.rad(-35),0,0)
aimerWeld.Part1 = aimer
if weaponAimed then
break
end
end
end)
end
pathToLocation(target)
end
else
yieldM4()
walkRandom()
end
end

function Died()
wait(300)
clone.Parent = workspace
game:GetService(“Debris”):AddItem(script.Parent,0)
end

myHuman.Died:Connect(Died)

while wait() do
main()
end
while true do
wait(10)
print(potentialTargets)
end

@Lodok3YT As you can see, it’s very long script.

Where is the error coming from? I need to know to troubleshoot.

Error: "Position is not a valid member of model”, https://gyazo.com/b21fb48862cfde62a5ad64448e7e2d4a
“if (myTorso.Position - torso.Position).magnitude < dist and human.Health > 0 then”
The main problem is “torso.position”.

You need capital P for position

@Lodok3YT wait no, i already capital it. forgot to capital P (not |roblox studio|, on comment reply)

Can you put the torso.Position in a print statement before the line?

@Lodok3YT WAIT!!! I FORGOT, I KNOW WHY position was error, because there is another NPC DUMMY https://gyazo.com/c8565139fcec6f9f543c1af8eac59b9e I JUST FOUND SOLUTION, i forgot (success) it just because it detect NPC torso but detect another NPC