I am currently doing a Handler for my npc, but i was wondering , how should i actually organize it?, Should i use oop or this in a modulescript?
return function(npc: Model)
-- logic
end
If i do this second method, I would need to Clone a Script from ServerStorage, Enable it and parent it to the npc, then require the Module
Just use a main server script that uses collection service. You most likely don’t need to use OOP unless you are dealing with very complex npcs. What exactly are you trying to achieve with this?
1 Like
I tried that but, It doesn’t works the way i want, so i do
coroutine.wrap(function()
CollectionService:GetInstanceAddedSignal("monster"):Connect(function(model)
require(rakehandler)(model)
end)
end)()
and then my rake handler :
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modules = ReplicatedStorage:WaitForChild("Modules")
local Shared = Modules:WaitForChild("Shared")
local Promise = require(Shared:WaitForChild("Promise"))
local AnimationController = Shared:WaitForChild("AnimationController")
local Utility = AnimationController:WaitForChild("Utility")
local Bin = require(Utility:WaitForChild("Bin"))
return function(rake: Model)
local Bin = Bin.new()
warn(rake)
local promiseLoop = Promise.new(function(resolve, reject)
while true do
task.wait(1)
print("Looped")
end
end):andThen(function(body)
warn(body)
end):catch(function(err)
if err then
warn(err)
end
end)
end
But when the model ( in this case the rake model) gets destroyed, the loop keeps running, and basically everything inside the function, that’s my only problem
Just check if the monster still exists and if not break the loop. Instead of while true you can do smth like while notDead and then set notDead to false by using the monster.Destroying event. Additionally, you should disconnect the event after the monster has been destroyed. Also, If you want to check monster health you can add an if statement in your loop or use humanoid.Health.Changed event. You also don’t need to wrap the function like you are doing currently because it is an event which will run in a new thread when called.