I want to make a script where if you are below a certain health, you will become in a “downed” state and have blur and a ColorCorrectionEffect applied to you.
I want to be able for this script to run even after character has respawned, but once the character respawns, all the functions that require the humanoid break even though I’ve re-defined the new humanoid and character inside my respawn function, any reasons why?
Script Location - StarterCharacterScripts
This has been bugging me for the past 2 days, any help would be appreciated!
wait()
-- Variables (Services)
local Lighting = game.Lighting
local ContentProvider = game:GetService("ContentProvider")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
-- Variables (Player, PlayerModules)
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Controls = require(plr.PlayerScripts.PlayerModule):GetControls()
-- Variables (Instances, Folders)
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local Sounds = game:GetService("ReplicatedStorage"):WaitForChild("Sounds")
-- Variables (Booleans)
local debounce = false
-- Dictionaries (Customizable)
local customizable = {
["LowHPHealth"] = 30; -- Minimum HP until effects apply.
["DownedHealth"] = 10; -- What health should the player be downed.
["GetUpHealth"] = 20; -- What health should the player be able to get up.
["Intensity"] = 10 -- Lower is darker, higher is lighter.
}
local function preloadAssets(assets)
-- Preloads assets inside an array.
ContentProvider:PreloadAsync(assets)
print("Preloaded assets")
end
-- Preloads all the sounds needed
preloadAssets(Sounds:GetChildren())
humanoid.HealthChanged:Connect(function(health)
print(char.Parent)
-- Variables (Instances, Integers)
local BlurEffect = Lighting.BlurLowHP
local ColourOverlay = Lighting.LowHPColourOverlay
local heartbeat = Sounds.LowHealthHeartbeatSound
local newcolor = 170/health
-- Variables (Tweens)
local blurTween = TweenService:Create(BlurEffect, TweenInfo.new(0.4, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0), {Size = math.clamp(customizable.LowHPHealth - humanoid.Health, 0, 22)})
local tintTween = TweenService:Create(ColourOverlay, TweenInfo.new(0.4, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0), {TintColor = Color3.new(math.clamp(1 - ((newcolor * customizable.Intensity) / 450), 0, 1), 0, 0)})
local tintTweenEnd = TweenService:Create(ColourOverlay, TweenInfo.new(0.4, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0), {TintColor = Color3.fromRGB(255, 255, 255)})
if health <= customizable.LowHPHealth then
-- Applies all the "LowHP" effects onto player.
BlurEffect.Enabled = true
ColourOverlay.Enabled = true
tintTween:Play()
blurTween:Play()
if not heartbeat.Playing then
heartbeat.Playing = true
end
heartbeat.Volume = (customizable.LowHPHealth - humanoid.Health)/5
-- Heartbeat becomes louder the lower the health.
if health <= customizable.DownedHealth then
Controls:Disable()
humanoid.Sit = true
elseif health >= customizable.GetUpHealth then
Controls:Enable()
humanoid.Sit = false
end
else
-- If the health remains above 30, it won't apply the effects.
heartbeat.Volume = 0
BlurEffect.Size = 0
BlurEffect.Enabled = false
tintTweenEnd:Play()
tintTweenEnd.Completed:Wait()
ColourOverlay.Enabled = false
heartbeat:Stop()
end
end)
humanoid.Died:Connect(function()
-- Variables (Instances)
local heartbeat = Sounds.LowHealthHeartbeatSound
local flatline = Sounds.FlatlineDeath
heartbeat:Stop()
flatline:Play()
end)
plr.CharacterAdded:Connect(function(character)
-- Variables (Instances)
local heartbeat = Sounds.LowHealthHeartbeatSound
local flatline = Sounds.FlatlineDeath
local BlurEffect = Lighting.BlurLowHP
local ColourOverlay = Lighting.LowHPColourOverlay
-- Re-define player variables.
char = character
humanoid = char:WaitForChild("Humanoid", 25)
-- Disable all the effects.
Controls:Enable()
flatline:Stop()
BlurEffect.Size = 0
BlurEffect.Enabled = false
ColourOverlay.Enabled = false
end)
Thanks!

