Hello,
I have some "cleanup code" that needs to be run right before the character gets removed, and because the local script is in StarterCharacterScripts, the script will get destroyed (and stop running) when the character gets removed. I tried using player.CharacterRemoving:Connect(function()), but that didn’t work.
Here is the “basic” premise of my code:
The lower a player gets on health, the higher the Size property of a BlurEffect located in workspace.CurrentCamera gets.
The blur is at its strongest when the player is at health 0, or after humanoid.Died is called.
The “cleanup code” destroys the BlurEffect in the camera.
The problem is that the blur doesn’t get destroyed when the character gets destroyed, so the screen stays blurred even after the player respawns.
I can’t use humanoid.Died to destroy the blur because the blur would disappear when the player dies if I did that.
Thank you for any help that you may offer. If you need more information, feel free to ask and I will try to provide the information.
Edit: I have now moved the script to StarterPlayerScripts, but the issue still persists.
This is the code I implemented: if humanoid.Health == 100 then print("e"); blurEffect:Destroy(); end
“e” does print, but the blur doesn’t get destroyed.
I have also now moved the script to StarterPlayerScripts and it seems that blur becomes “indestructible” after the player dies…
Thats the problem, it appears that camera:GetChildren() doesn’t work, and for some reason my script creates a new blur when the player dies, which means that camera.<blurName> won’t be a feasable method of finding the blur.
Hello, I ended up figuring out what was causing the issue.
Because a new humanoid is created when the player respawns, my connection for updating the blur amount was checking the health of old humanoid (whos health was 0) and not the new one (which has a health of 100).
This is how I fixed the problem:
-- Old code
local player = game.Players.LocalPlayer;
local character = player.Character or player.CharacterAdded:Wait();
local humanoid = character:FindFirstChildOfClass("Humanoid");
local blurAmount;
-- Old code
humanoid.HealthChanged:Connect(function()
-- Calculate blur amount
end)
-- New code
local HCConnection = humanoid.HealthChanged:Connect(function()
-- Calculate blur amount
end)
player.CharacterAdded:Connect(function()
character = player.Character or player.CharacterAdded:Wait();
humanoid = character:FindFirstChildOfClass("Humanoid");
HCConnection:Disconnect();
HCConnection = humanoid.HealthChanged:Connect(function()
-- Calculate blur amount
end)
blurAmount = 0;
end)