I have a script for an AI, and whenever it’s jumpscaring I instantly stop it from patroling, break the task.wait() loop and spawn in a new AI script. Is there an easier way of doing this, preferably without making a new script?
Main ServerScript in AI model
while task.wait() do
if AI.Jumpscaring.Value == false then
patrol()
else
warn("Jumpscaring")
break
end
end
Kill ServerScript in AI model
AI.Main:Destroy()
local ClonedAI = script.Main:Clone()
ClonedAI.Parent = AI
ClonedAI.Enabled = true
Ah gotcha, would it be possible for some sample code? Or are there any good sources for coroutines as I never really worked with them before. But regardless, thank you for the idea!