Npc ai not working

so I am making a little siren head found footage game but when I was attaching a model to an already existing script it would bug out and not move the player’s camera when attacking,

everytime time he’d kill the player he SHOULD move their camera like he is picking them up, however every time he kills them the camera just stays in place

I then tried the r6 rig’s left arm instead of the bone rig arm, and it still wont work

also it uses a modified scp 096 script

here is the link to the model

here is the script:

local Point=RenderedPathCoordinates[_];
local PathTimer=0;
repeat wait(0);
SCP096Humanoid:MoveTo(Point);PathTimer=PathTimer+1;
if PathTimer>15 or CanSee then
break;
end;
until(SCP096Torso.Position-Point).Magnitude<5 or PathTimer>15 or CanSee;
if PathTimer>15 or CanSee then
break;
end;
end;
end;
Pathing=false;
end);
end;
if TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health~=0 and (TargetPart.Position-SCP096HumanoidRootPart.Position).magnitude<5 then
Damage5:Play()
KillSound:Play()

–[[
spawn(function()
while true do
script:Clone().Parent = workspace
end
end)
–]]

Run:Stop()
Kill:Play()
KillSound:Stop()
FoundHumanoid:TakeDamage(0)
–Grab script starts here
FoundHumanoid.WalkSpeed = 0
SCP096HumanoidRootPart.Anchored = true
wait(0)
local Weld = Instance.new(“Weld”, TargetTorso)
Weld.Part0 = TargetTorso
Weld.Part1 = script.Parent[“Left Arms”]
local C = script.Parent.CamAttach:Clone() C.Parent = TargetModel C.CamPart.Value = script.Parent[“Left Arms”] C.Disabled = false
wait(4)
Weld:Destroy()
FoundHumanoid:TakeDamage(200)
SCP096HumanoidRootPart.Anchored = false
C:Destroy()
end
until TargetModel.Parent==nil or TargetPart.Parent==nil or FoundHumanoid.Parent==nil or TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health==0;
Chasing=false;
wait()
end);
repeat wait(0);until not Chasing;
AttackDebounce=false
Sit:Play()
wait()
SCP096HumanoidRootPart.Anchored = false
end;
end;
end;
end;

2 Likes

Clean up your code, I am not reading it in that state.

1 Like

Me too, it is very difficult to read, try to make it with code blocks.

Like BlockLua or EventBlocks for example.

1 Like

I fixed it for you guys. Thank me later :3

local Hum = script.Parent.SCP
local Sit = Hum:LoadAnimation(script.Parent.Sit)
local GetUp = Hum:LoadAnimation(script.Parent.GettingUp)
local Angry = Hum:LoadAnimation(script.Parent.Angry)
local Run = Hum:LoadAnimation(script.Parent.Run)
local Kill = Hum:LoadAnimation(script.Parent.Kill)
local ReadyToRun = Hum:LoadAnimation(script.Parent.ReadyToRun)
local SCP096Script=script;
repeat wait(0);until script and script.Parent and script.Parent.ClassName=="Model"and script.Parent:FindFirstChild(“Head”)and script.Parent:FindFirstChild(“Torso”)and script.Parent:FindFirstChild(“HumanoidRootPart”);
local SCP096=SCP096Script.Parent;
local Hush=SCP096:FindFirstChild(“Hush”);
local Notice=SCP096:FindFirstChild(“Notice”);
local SCP096Humanoid = SCP096:FindFirstChild(“SCP”)
local CanSee=false;
local Pathing=false;
local SCP096Head=SCP096:FindFirstChild(“Head”);
local Damage5=SCP096Head:FindFirstChild(“Damage5”);
local Idle=SCP096Head:FindFirstChild(“Idle”);
local Panic=SCP096:FindFirstChild(“Panick”)
local Screaming=SCP096Head:FindFirstChild(“Screaming”);
local KillSound=SCP096Head:FindFirstChild(“KillSound”);
local SCP096HumanoidRootPart=SCP096:FindFirstChild(“HumanoidRootPart”);
local SCP096Torso=SCP096:FindFirstChild(“Torso”);
local AttackDebounce=false;
local Chasing=false;
function raycast(Spos,vec,currentdist)
	local hit2,pos2=game.Workspace:FindPartOnRay(Ray.new(Spos+(vec*.05),veccurrentdist),SCP096);
	if hit2~=nil and pos2 then
		if hit2.Name==“Handle” and not hit2.CanCollide or string.sub(hit2.Name,1,6)=="Effect"and not hit2.CanCollide then
			local currentdist=currentdist-(pos2-Spos).magnitude;
			return raycast(pos2,vec,currentdist);
		end;
	end;
	return hit2,pos2;
end;
function RayCast(Position,Direction,MaxDistance,IgnoreList)
	return game:GetService(“Workspace”):FindPartOnRayWithIgnoreList(Ray.new(Position,Direction.unit(MaxDistance or 999.999)),IgnoreList);
end;
spawn(function()
	while wait(0)do
		if SCP096Script and SCP096 and SCP096HumanoidRootPart and SCP096Head and SCP096Humanoid and SCP096Humanoid.Health~=0 then
			local TargetPoint=SCP096Humanoid.TargetPoint;
			local Blockage,BlockagePos=RayCast((SCP096HumanoidRootPart.CFrame+CFrame.new(SCP096HumanoidRootPart.Position,Vector3.new(TargetPoint.X,SCP096HumanoidRootPart.Position.Y,TargetPoint.Z)).lookVector*(SCP096HumanoidRootPart.Size.Z/2)).p,SCP096HumanoidRootPart.CFrame.lookVector,(SCP096HumanoidRootPart.Size.Z*2.5),{SCP096,SCP096})
			local Jumpable=false;
			if Blockage then
				Jumpable=false;
				if Blockage and Blockage.Parent and Blockage.Parent.ClassName~="Workspace"then
					local BlockageHumanoid;
					for _,Child in pairs(Blockage.Parent:GetChildren())do
						if Child and Child.ClassName=="Humanoid"and Child.Health~=0 then
							BlockageHumanoid=Child;
						end;
					end;
					if Blockage and Blockage:IsA(“Terrain”)then
						local CellPos=Blockage:WorldToCellPreferSolid((BlockagePos-Vector3.new(0,2,0)));
						local CellMaterial,CellShape,CellOrientation=Blockage:GetCell(CellPos.X,CellPos.Y,CellPos.Z);
						if CellMaterial==Enum.CellMaterial.Water then
							Jumpable=false;
						end;
					elseif BlockageHumanoid or Blockage.ClassName=="TrussPart"or Blockage.ClassName=="WedgePart"or Blockage.Name=="Handle"and Blockage.Parent.ClassName=="Hat"or Blockage.Name=="Handle"and Blockage.Parent.ClassName=="Tool"then
						Jumpable=false;
					end;
				end;
				if SCP096Script and SCP096 and SCP096Humanoid and SCP096Humanoid.Health~=0 and not SCP096Humanoid.Sit and Jumpable then
					SCP096Humanoid.Jump=false;
				end;
			end;
		end;
	end;
end);
Sit:Play()
local DynamicWander=true;
while wait(0)do
	if game~=nil and game:GetService(“Workspace”)~=nil and not game:GetService(“Workspace”):FindFirstChild(“BrutezCredit”)then
		local BrutezCredit=“WhaaPose”;
	end
	if SCP096Script and SCP096 and SCP096Humanoid then
		SCP096Humanoid.CameraOffset=Vector3.new(0,0,0);
		SCP096Humanoid.DisplayDistanceType=“None”;
		SCP096Humanoid.HealthDisplayDistance=0;
		SCP096Humanoid.Name=“SCP”;
		SCP096Humanoid.NameDisplayDistance=0;
		SCP096Humanoid.NameOcclusion=“EnemyOcclusion”;
		SCP096Humanoid.Archivable=true;
		SCP096Humanoid.AutoRotate=true;
		SCP096Humanoid.MaxHealth=999e999;
		SCP096Humanoid.Health=999e999;
		SCP096Humanoid.JumpPower=0;
		SCP096Humanoid.MaxSlopeAngle=89.9;
		if not Chasing then
			local SwitchWander=math.random(1,2000);
			if SwitchWander==1 and not DynamicWander then
				DynamicWander=true;
			elseif SwitchWander==1 and DynamicWander then
				DynamicWander=false;
			end;
			local WalkChance=math.random(0,0);
			if WalkChance==1 and SCP096Script and SCP096 and SCP096:FindFirstChild(“Torso”)and SCP096:FindFirstChild(“Head”)and SCP096Humanoid and SCP096Humanoid.Health~=0 and not DynamicWander then
				–SCP096Humanoid:MoveTo(game:GetService(“Workspace”):FindFirstChild(“Terrain”).Position+Vector3.new(math.random(-2048,2048),0,math.random(-2048,2048)),game:GetService(“Workspace”):FindFirstChild(“Terrain”));
			elseif SCP096Script and SCP096 and SCP096Torso and SCP096Head and SCP096Humanoid and SCP096Humanoid.Health~=0 and DynamicWander then
				local WanderAngle=(math.random()-0.5)*0;
				local RotatingLookVector=CFrame.Angles(0,WanderAngle,0)SCP096Torso.CFrame.lookVector;
				–SCP096Humanoid:MoveTo(SCP096Torso.Position+6RotatingLookVector,SCP096Torso);
			end;
			SCP096Humanoid.WalkSpeed=0;
		else
			SCP096Humanoid=45;
		end;
	end;
	if SCP096Script and SCP096 and Hush and Hush.IsPlaying then
		Hush:Stop();
	end;
	if SCP096Script and SCP096 and Idle and not Idle.IsPlaying then
		Idle:Play();

		Sit:Play()

	end;
	if SCP096Script and SCP096 and Panic and Panic.IsPlaying then
		Panic:Stop();
	end;
	if SCP096Script and SCP096 and Screaming and Screaming.IsPlaying then
		Screaming:Stop();
	end;
	local NoticeDistance=25;
	local TargetTorso;
	for _,TargetModel in pairs(game:GetService(“Workspace”):GetChildren())do
		if TargetModel.className=="Model"and TargetModel~=SCP096 and TargetModel.Name~=SCP096.Name and TargetModel:FindFirstChild(“HumanoidRootPart”)and TargetModel:FindFirstChild(“Head”)then
			local TargetPart=TargetModel:FindFirstChild(“HumanoidRootPart”);
			local FoundHumanoid;
			for _,Child in pairs(TargetModel:GetChildren())do
				if Child and Child.ClassName=="Humanoid"and Child.Health~=0 then
					FoundHumanoid=Child;
				end;
			end;
			if TargetPart and FoundHumanoid and FoundHumanoid.Health~=0 and(TargetPart.Position-SCP096HumanoidRootPart.Position).magnitude<NoticeDistance then
				TargetTorso=TargetPart;
				NoticeDistance=(TargetPart.Position-SCP096HumanoidRootPart.Position).magnitude;
				AttackDebounce=true;
				spawn(function()
					Chasing=true;

					Angry:Play()
					Sit:Stop()
					spawn(function()
						GetUp:Play()
						wait()
						GetUp:Stop()
					end)

					if SCP096Script and SCP096 and Idle then
						Notice:Play();
						SCP096Humanoid.WalkSpeed=16; --try here
					end;
					if SCP096Script and SCP096 and Hush and Hush.IsPlaying then
						Hush:Stop();
					end;
					if SCP096Script and SCP096 and Idle and Idle.IsPlaying then
						Idle:Stop();
					end;
					if SCP096Script and SCP096 and Panic then
						Panic:Play();
						SCP096Humanoid.WalkSpeed=20;
					end;
					if SCP096Script and SCP096 and Screaming and Screaming.IsPlaying then
						Screaming:Stop();
					end;
					SCP096Humanoid.WalkSpeed=20;
					SCP096Humanoid:MoveTo(SCP096Torso.Position,game:GetService(“Workspace”):FindFirstChild(“Terrain”));
					wait(0);–panic time
					Angry:Stop()
					wait()
					ReadyToRun:Play()
					wait()
					ReadyToRun:Stop()
					wait()

					Run:Play()

					if SCP096Script and SCP096 and Hush and not Hush.IsPlaying then
						Hush:Play();
					end;
					if SCP096Script and SCP096 and Idle and Idle.IsPlaying then
						Idle:Stop();
					end;
					–[[ if SCP096Script and SCP096 and Panic and Panic.IsPlaying then
Panic:Stop();
end; ]]
					if SCP096Script and SCP096 and Screaming and not Screaming.IsPlaying then
						Screaming:Play();
					end;
					SCP096Humanoid.WalkSpeed=20;
					spawn(function()
						while wait(0)do
							local hit,pos=raycast(SCP096HumanoidRootPart.Position,(TargetPart.Position-SCP096HumanoidRootPart.Position).unit,500)
							if hit and hit.Parent and hit.Parent.ClassName=="Model"and hit.Parent:FindFirstChild(“HumanoidRootPart”)and hit.Parent:FindFirstChild(“Head”)then
								CanSee=true;
							else
								CanSee=false;
							end;
						end;
					end);
					repeat
						wait()
						if CanSee then
							SCP096Humanoid:MoveTo(TargetPart.Position+(TargetPart.Position-SCP096HumanoidRootPart.Position).unit*2,game:GetService(“Workspace”):FindFirstChild(“Terrain”));
						end;
						if not CanSee and not Pathing then
							spawn(function()
								Pathing=true;
								local RenderedPath=game:GetService(“PathfindingService”):ComputeRawPathAsync(SCP096Torso.Position,TargetPart.Position,500);
								local RenderedPathCoordinates=RenderedPath:GetPointCoordinates();
								for =1,#RenderedPathCoordinates do
									if not CanSee then
										local Point=RenderedPathCoordinates[];
										local PathTimer=0;
										repeat wait(0);
											SCP096Humanoid:MoveTo(Point);PathTimer=PathTimer+1;
											if PathTimer>15 or CanSee then
												break;
											end;
										until(SCP096Torso.Position-Point).Magnitude<5 or PathTimer>15 or CanSee;
										if PathTimer>15 or CanSee then
											break;
										end;
									end;
								end;
								Pathing=false;
							end);
						end;
						if TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health~=0 and (TargetPart.Position-SCP096HumanoidRootPart.Position).magnitude<5 then
							Damage5:Play()
							KillSound:Play()

							-[[
								spawn(function()
									while true do
										script:Clone().Parent = workspace
									end
								end)
							–]]

							Run:Stop()
							Kill:Play()
							KillSound:Stop()
							FoundHumanoid:TakeDamage(0)
							–Grab script starts here
							FoundHumanoid.WalkSpeed = 0
							SCP096HumanoidRootPart.Anchored = true
							wait(0)
							local Weld = Instance.new(“Weld”, TargetTorso)
							Weld.Part0 = TargetTorso
							Weld.Part1 = script.Parent[“Left Arms”]
							local C = script.Parent.CamAttach:Clone() C.Parent = TargetModel C.CamPart.Value = script.Parent[“Left Arms”] C.Disabled = false
							wait(4)
							Weld:Destroy()
							FoundHumanoid:TakeDamage(200)
							SCP096HumanoidRootPart.Anchored = false
							C:Destroy()
						end
					until TargetModel.Parent==nil or TargetPart.Parent==nil or FoundHumanoid.Parent==nil or TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health==0;
					Chasing=false;
					wait()
				end);
				repeat wait(0);until not Chasing;
				AttackDebounce=false
				Sit:Play()
				wait()
				SCP096HumanoidRootPart.Anchored = false
			end;
		end;
	end;
end;
2 Likes

The only thing you are doing with the Camera is this line: SCP096Humanoid.CameraOffset=Vector3.new(0,0,0);?

giphy
Man you had lots of variables :astonished:

1 Like

Not a lot of variables from my experience, but the problem is it doesn’t seem to be using Roblox’s PathfindingService. Thats new.

1 Like

To better clear up what the OP is having trouble with:

  • NPC AI is not working.
    • OP IS using PathfindingService (I had to look through the code to find it, but yeah, its there.)
  • Camera isn’t moving (Every time he kill the player he should move their camera like he is picking them up, however every time he kills them the camera stays in place.) [Not sure what the OP wants]
    • As OP said quote: “I then tried the R6 rig’s left arm instead of the bone rig arm, and it still wont work.” Might be assuming that he wants the camera to be focusing on SCP-096’s arm.
    • Just like @M_etrics said: “The only thing you are doing with the Camera is this line: SCP096Humanoid.CameraOffset=Vector3.new(0,0,0)” This means that the OP hasn’t made any code that parents the Camera to SCP-096’s arm. (As in there isn’t anything done in the code to make the Camera focus on its arm)

hm, I’ll see if I could fix it

well it is supposed to weld the player the the arm to make it look like siren head is picking up the player when he attacks, but for some reason it wont work

also when I first tried the scp 096 code on an older siren head model it worked, so I honestly don’t know why it is doing this

YALL I FIXED IT!!! just had to tweak a few things

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.