My FNaF AI system isn't working as intended

I want to achieve a fully functional AI system, meaning it moves from 1 place to another, and not hop across the map. And a Jump scare when you die.

My AI system is extremely quick even though I set the AI pretty low for the most part. But, when the animatronic gets to my door, it doesn’t fire the jump scare.

Another issue I had, was when the animatronic would stop right before he was at the door.

I’ve tried adding waits, attempting to rework the movement opportunity system, I’ve tried. I did look for solutions, but nothing was that helpful.

Hey! I wanted help with a AI system I was making. It’s based on FNaF’s AI system. Only problem. It won’t work. I just want to find out what the problem is, so I can fix it.
Heres the script:

–script start
ServerStorage = game.ServerStorage
local player = game.Players.LocalPlayer
Seconde = wait()

game.Workspace[“Freddy’s Laugh”]:Play()
World = game.Workspace

local Place = Instance.new(“IntValue”)
Place.Value = 1
local model = game.Workspace.Bacon1

Place.Changed:Connect(function()

if Place.Value == 1 then
	model:SetPrimaryPartCFrame(game.ServerStorage["Bacon1.5"].PrimaryPart.CFrame)
	
end
if Place.Value == 2 then
	model:SetPrimaryPartCFrame(game.ServerStorage.Bacon2.PrimaryPart.CFrame)
	
end
if Place.Value == 3 then
	model:SetPrimaryPartCFrame(game.ServerStorage.Bacon3.PrimaryPart.CFrame)
	
end
if Place.Value == 4 then
	model:SetPrimaryPartCFrame(game.ServerStorage.Bacon4.PrimaryPart.CFrame)
	--Moving to places
	
end
if Place.Value == 5 then
	workspace.Everythingno:FireAllClients()
      workspace.Jumpscare:FireAllClients()
	--Jumpscare is supposed to fire here.
end




end)

while true do
local AI = math.random(1,5)
if Place.Value >= 6 then
Place.Value = 5
end
wait(6)
local second = math.random(1,20)

if second <= AI then
	
	wait(6)
	print("Movement successful.")
	for i = 1, 1050 do
		wait(0.01)
	end
	Place.Value = Place.Value + math.random(-1,1)
else
	wait(5)
	print("Movement failed.")

	end

end

1 Like

can you post the local script that recieves the jumpscare? It might help to move your remote event “Everythingno” to ReplicatedStorage too.

Paste your scripts with three back ticks like so

```
– paste your code here!!
function()
end
```

Alright.
Sorry for the messy code!
The recieving script:

game.Workspace.Jumpscare.OnServerEvent:Connect(function()
workspace.Jumpscare:FireAllClients()
end)

The one who fires the Jumpscare:

workspace.Everythingno.OnClientEvent:Connect(function()
script.Parent.Camera.Visible = false
script.Parent.CameraDown.Visible = false
script.Parent.DiningRoomButton.Visible = false
script.Parent.Piratescovebutton.Visible = false
script.Parent.Bathroombutton.Visible = false
script.Parent.Supplyclosetbutton.Visible = false
script.Parent.Backroombutton.Visible = false
script.Parent.LeftHallButton.Visible = false
script.Parent.RightHallButton.Visible = false
script.Parent.RightHallCornerButton.Visible = false
script.Parent.StageButton.Visible = false
script.Parent.LeftCornerButton.Visible = false
script.Parent.staticframe.Visible = false
script.Parent.staticframe2.Visible = false
workspace.Jumpscare:FireServer()
end)

Everything seems in order, aside from moving the remote events to ReplicatedStorage. do the listed objects turn invisible?

Well, yes. They do. But, the animatronic script won’t fire “Everythingno”, for some strange reason.

Does the movement script itself have a problem with how it makes the animatronic move with values?

Sounds like the animatronic script is firing Everythingno? are you referring to this part?

Place.Changed:Connect(function()
--- etc ...

if Place.Value == 5 then
    workspace.Everythingno:FireAllClients() -- this fires
    workspace.Jumpscare:FireAllClients()
	--Jumpscare is supposed to fire here.
end
end)

Yep, I am. The animatronic place value never gets to 5, and doesn’t fires the event as a result.

It is random, might just not be happening so far. Pretty rare to flip a coin and land on heads 5 times in a row tbh.

If you set the event to fire at 2 or 3 does it still not fire?

I’ll do that. But the system prints out each time it has a successful movement opportunity.

A successful movement could be:

  • -1, I assume the AI goes backwards
  • 0 they stay still
  • 1 they advance towards the jumpscare

To get to 5 could take a very long time, especially with your long waits

Yeah… It won’t fire. The character stays in place even when it has a successful opportunity.

	wait(6)
	print("Movement successful.")
	for i = 1, 1050 do -- for-wait cand be reduced to just wait(10.5), but is much likely to be longer
		wait(0.01)
	end
	Place.Value = Place.Value + math.random(-1,1)

This prints “Movement successful.” then after 10 seconds will actually update the place value. Are you waiting 10 seconds after the print shows?

Eitherway I would certainly remove the for-wait loop, waits must be at least one frame long, so your looking at aleast 1050 * 0.033 = 34.6 seconds of a wait

Yeah, I am. The thing is that it still doesn’t move. And I added an If statement sending the place value back to 1 if the value goes under 0.

Keep in mind, I based it off FNaF’s AI system.

I’ve done the math and updated my reply, the for-wait loop is probably closer to 35 seconds than 10.

I highly suggest removing the for-wait loop and replace it with a task.wait(10). Also put a print(Place.Value) after it’s updated.

Oh. The character is based of Freddy’s AI in Five Nights at Freddys. He has a countdown before he moves. I tried to make the countdown, which resulted in it waiting 35 seconds instead of 15.

I updated the script, he still stays in place.

does it print anything? what is Place.Value after it is updated?

Yep. It printed, “Movement successful.”