Hello. I wanted to make a script that could make a potato move around similar to how the animatronics moved in Five Nights at Freddy’s. I did this by making a small table for each possible position with the next possible positions. However, when I run it, it repeats the same position its in infinitely. I don’t have any idea why this is happening.
Here’s the script;
local potatoKiller = workspace:WaitForChild("PotatoKiller")
local whereIsPotatoKiller = potatoKiller:WaitForChild("WhereIsPotatoKillerValue")
local possiblePotatoLocations = workspace:WaitForChild("PossiblePotatoLocations")
local pl1 = possiblePotatoLocations.PL1
local pl2 = possiblePotatoLocations.PL2
local pl3 = possiblePotatoLocations.PL3
local pl4 = possiblePotatoLocations.PL4
local pl5 = possiblePotatoLocations.PL5 --kill
local pl6 = possiblePotatoLocations.PL6
local pl7 = possiblePotatoLocations.PL7 --kill
local pl8 = possiblePotatoLocations.PL8
local pl9 = possiblePotatoLocations.PL9
local pl10 = possiblePotatoLocations.PL10 --kill
local pl11 = possiblePotatoLocations.PL11
local pl12 = possiblePotatoLocations.PL12
local pl13 = possiblePotatoLocations.PL13
local pl1PossiblePositions = {pl13,pl11,pl12}
local pl2PossiblePositions = {pl12,pl3}
local pl3PossiblePositions = {pl4,pl2}
local pl4PossiblePositions = {pl5,pl3}
local pl5PossiblePositions = {}
local pl6PossiblePositions = {pl8,pl13,pl7}
local pl7PossiblePositions = {}
local pl8PossiblePositions = {pl6,pl4,pl3}
local pl9PossiblePositions = {pl10}
local pl10PossiblePositions = {}
local pl11PossiblePositions = {pl1,pl9}
local pl12PossiblePositions = {pl2}
local pl13PossiblePositions = {pl6,pl1}
local possibleNextPotatoLocations = possiblePotatoLocations:WaitForChild("PL1"):GetChildren()
local waitTime = math.random(5,20)
local nextPotatoPosition
local debounce = false
nextPotatoPosition = pl1PossiblePositions[math.random(1,#pl1PossiblePositions)]
wait(waitTime)
potatoKiller.CFrame = pl1.CFrame
while true do
waitTime = math.random(5,20)
wait(waitTime)
debounce = false
potatoKiller.CFrame = nextPotatoPosition.CFrame
if nextPotatoPosition == "PL1" and debounce == false then
nextPotatoPosition = pl1PossiblePositions[math.random(1,#pl1PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL2" and debounce == false then
nextPotatoPosition = pl2PossiblePositions[math.random(1,#pl2PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL3" and debounce == false then
nextPotatoPosition = pl3PossiblePositions[math.random(1,#pl3PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL4" and debounce == false then
nextPotatoPosition = pl4PossiblePositions[math.random(1,#pl4PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL5" and debounce == false then
print("death")
elseif nextPotatoPosition == "PL6" and debounce == false then
nextPotatoPosition = pl6PossiblePositions[math.random(1,#pl6PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL7" and debounce == false then
print("death")
elseif nextPotatoPosition == "PL8" and debounce == false then
nextPotatoPosition = pl8PossiblePositions[math.random(1,#pl8PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL9" and debounce == false then
nextPotatoPosition = pl9PossiblePositions[math.random(1,#pl9PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL10" and debounce == false then
print("death")
elseif nextPotatoPosition == "PL11" and debounce == false then
nextPotatoPosition = pl11PossiblePositions[math.random(1,#pl11PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL12" and debounce == false then
nextPotatoPosition = pl12PossiblePositions[math.random(1,#pl12PossiblePositions)]
debounce = true
elseif nextPotatoPosition == "PL13" and debounce == false then
nextPotatoPosition = pl13PossiblePositions[math.random(1,#pl13PossiblePositions)]
debounce = true
end
print(nextPotatoPosition)
end