I got a problem. Im currently doing a robber arrest system with my npc pathfinding system.
So there is a proximityprompt inside the robber and when the player triggers it, there should be an animation. This is all working but, the pathfinding system has a while true do loop and it would break when the Robber gets arrested cuz he wont be able to walk any further.
So how could I check if the value gets true and then skip parts of the while loop?`
while true do
move
move
move β lets say the robber gets arrested while moving to this point (it could be any other point too), how could I now skip all the other moves and just do the NPC:Destroy()
move
move
NPC:Destroy()
The real problem is that if i do an if statement, the loop will only check it 1 time while running, but i need it to check every second.
You can use a flag variable to track whether the robber has been arrested or not. In your while loop, you can check the value of the flag and choose to skip the rest of the loop if it is true.
Hereβs an example of how you could implement this:
local arrested = false
while true do if arrested then break end
move
move
move
if arrested then break end
move
move
NPC:Destroy()
end
To set the flag to true, you can use a function like this:
function arrestRobber() arrested = true end
Then, in your proximity prompt event handler, you can call the arrestRobber function to set the flag to true and break out of the loop.