EntityHandler.EntityStates = {
Patrol = function(Npc,patrolFolder,path)
while true do
for _,goal in pairs(patrolFolder:GetChildren()) do
local success,errormsg = pcall(function()
return path:ComputeAsync(Npc.HumanoidRootPart.Position,goal.Position)
end)
if success then
for _,waypoint in pairs(path:GetWaypoints()) do
Npc.Humanoid:MoveTo(waypoint.Position)
Npc.Humanoid.MoveToFinished:Wait()
end
else
warn(errormsg)
end
end
end
end,
}
#Should I use RunService or a true loop for this?
1 messages · Page 1 of 1 (latest)
if I did heartbeat it would run more than it would need to and also I tried didn't work,. while true loop is fine right
its not a serial script btw
Although, I do wanna be able to stop it outside of this script
task.tancel()
local PS = game:GetService("PathfindingService")
local path = PS:CreatePath()
local SCS = game:GetService("ServerScriptService")
local EntityHandler = require(SCS.EntityHandler)
local thread = EntityHandler.EntityStates.Patrol(game.Workspace.NPC1,game.Workspace.NPC1Patrol,path)
task.cancel(thread)
This is the other script, like this?
it didn't work
by outside of script I mean in another script, not another block of code inside the same script object
a normal function isnt a thread
u need to use task.spawn
local PS = game:GetService("PathfindingService")
local path = PS:CreatePath()
local SCS = game:GetService("ServerScriptService")
local EntityHandler = require(SCS.EntityHandler)
task.spawn(EntityHandler.EntityStates.Patrol(game.Workspace.NPC1,game.Workspace.NPC1Patrol,path))
task.wait(1)
task.cancel()
idk how to describe what I want to be cancelled
** You are now Level 12! **
local PS = game:GetService("PathfindingService")
local path = PS:CreatePath()
local SCS = game:GetService("ServerScriptService")
local EntityHandler = require(SCS.EntityHandler)
local thread = task.spawn(function()
EntityHandler.EntityStates.Patrol(game.Workspace.NPC1,game.Workspace.NPC1Patrol,path)
end)
task.wait(1)
task.cancel(thread)
oh like this
didn't work
-- Task/thread
local t = task.spawn(function()
while true do
print("Running")
task.wait(1) -- yields so it can be canceled
end
end)
task.cancel(t) -- Stops the task at next yield```
magic
from another script
how
oh because of my modulescript
im dumb
listenm its 6 am
im not the brightest tool in the shed rn
I can't contribute much to the coding part, but
I believe heartbeat provides a delta time parameter, you can use that to slow down the amount of times it plays in seconds
Oh damn