i have a module script which has an module:activate and a module:disable, with another function module:create_agent
in the create agent function, there is this line self.update_connection = nil, in the active function the update_connection gets changed to a heartbeat loop like this
the disable function disconnects the update connection
the problem is this line self.update_connection = RunService.Heartbeat:Connect(function(dt) causes the error in the title
this is the full code for better visualization:
function PathfindingAgent:CreateAgent(agent, agent_settings)
local self = setmetatable({}, PathfindingAgent)
--stuff and stuff
self.update_connection = nil
--more stuff
return self
end
function PathfindingAgent:Activate()
self.update_connection = RunService.Heartbeat:Connect(function(dt) --this the error
PathfindingAgent:Update() --dt
end)
self.is_activated = true
end
function PathfindingAgent:Disable()
if not self.is_activated then return end
self.update_connection:Disconnect()
self.current_movement_state = self.Movemenet_States.Idle
end
function PathfindingAgent:Disable()
if not self.is_activated then return end
self.update_connection:Disconnect()
self.current_movement_state = self.movement_states.Idle
end
doesnt fix the error but did stop a future error so gj ig
i may have set it wrong but im pretty sure it is set?
local PathfindingAgent = {}
PathfindingAgent.__index = PathfindingAgent --this is at the top of module
--inside the create agent code
self = setmetatable({}, PathfindingAgent)
could you try the run service thing for me, i just wanna see if it prints or no.
function PathfindingAgent:Activate()
if not RunService.Heartbeat then
error("RunService.Heartbeat is nil")
end
self.update_connection = RunService.Heartbeat:Connect(function(dt)
PathfindingAgent:Update() --dt
end)
self.is_activated = true
end
If it doesn’t i know the issue
Other troubleshoots
function PathfindingAgent:Activate()
if not self then
error("self is nil")
end
if not self.update_connection then
error("self.update_connection is nil")
end
self.update_connection = RunService.Heartbeat:Connect(function(dt)
PathfindingAgent:Update() --dt
end)
self.is_activated = true
end
works however in the module when i print(self.Agent) instead of printing BigLenny it prints the Agent_Settings instead? and when printing self.Settings it prints nil
full function code:
function PathfindingAgent:CreateAgent(agent, agent_settings)
self = setmetatable({}, PathfindingAgent)
self.Agent = agent
self.Settings = agent_settings
self.is_activated = nil
self.movement_states = {
InPath = 0,
WaitingForPath = 1,
Idling = 2,
Dead = 3,
Pathfinding = 4,
Chasing = 5,
}
self.status_states = {
Activated = 0,
DeActivated = 1,
Contained = 2,
}
self.curr_movement_state = self.movement_states.Idling
self.curr_status_state = self.status_states.DeActivated
self.update_connection = nil
print(self.Agent) --SHOULD print BigLenny, instead prints settings bruh
print(self.Settings) --prints nil bruh
self.Humanoid = self.Agent:WaitForChild("Humanoid")
self.HumanoidRootPart = self.Agent:WaitForChild("HumanoidRootPart")
self.Torso = self.Agent:WaitForChild("Torso")
_, self.bounding_box = self.Agent:GetBoundingBox()
for i, part in pairs(self.Agent:GetChildren()) do
if part:IsA("BasePart") then
part:SetNetworkOwner(nil)
end
end
return self
end