Died = function()
local Humanoid = Character:FindFirstChild("Humanoid")
local Connection
Connection = Humanoid.Died:Connect(function()
self:Died(Humanoid)
end)
if Humanoid.Health > 0 then
Connection:Disconnect()
end
end,
Functions.Died()
function NightVision:Died(Humanoid: Humanoid)
if self.Activated and not self.Cooldown and Humanoid.Health == 0 then
print(self.Activated)
Lighting.OutdoorAmbient = self.Default
for _, Object in Lighting:GetChildren() do
if Object.Name == "NBlur" then
Object:Destroy()
end
if Object.Name == "NLight" then
Object:Destroy()
end
end
self.Activated = false
print(self.Activated)
end
end
(Yes, I do know that I can use Maid for these connections…)
Of course, this is not all the code, but the prints do not fire for some reason. However, the OutdoorAmbient returns to default, and the “NBlur” and “NLight” get destroyed.
self.Activated does not seem to do anything, but it does in the other 200 lines of code…
If you can help me out, that would be great. Thanks.
It runs on the network owner of the humanoid. If the humanoid died on the client, it will only run on the client’s scripts. If this is an NPC, it will run on the server.
Also the “self” on the first died function, is referring to an already declared object, like local obj = NightVision.create() or local obj = NightVision.new()
Just for organization purposes, I just have a table of all the client function I am using for the module.
(The table is called “Functions”)
Functions.”Whatever the name of it is”
Where I initialized these functions are all in a function where self is already declared as “NightVision”.
After some debugging, I “fixed” the Humanoid.Died function, but now I ran into a new error.
local function PlayerAdded(Player: Player)
if Player.Character then
Player.CharacterAdded:Connect(function(Character)
return Character
end)
else
repeat task.wait() until Player.Character
return Player.Character
end
end
local Character = PlayerAdded(self.Player)
local Head = Character:WaitForChild("Head")
local NVG
NVG = self.Player.Backpack:FindFirstChild("NVG")
function NightVision:Died()
if self.Activated then
DestroyLighting(self)
self.Activated = false
self.Cooldown = false
end
end
Died = function()
local Humanoid = Character:FindFirstChild("Humanoid")
self.Maid:GiveTask(
Humanoid.Died:Connect(function()
self:Died()
end)
)
end,
}
Functions.Died()
It does not detect the new character variable. I know this can be fixed easily, but my brain does not seem to be working right now.