Hello, so, I have a script that puts a GUI and some effects whenever the player's health is below or equals 15%, it works fine on the launch, but whenever the player respawns, the script stops working. The script is put into StarterPlayerScripts and is a LocalScript. Here's the code:
--vars local L = game:GetService("Lighting") local TS = game:GetService("TweenService") local Plr = game:GetService("Players").LocalPlayer local CC = Instance.new("ColorCorrectionEffect",L) CC.Name = "NearDeathEffect" local gui = Instance.new("ScreenGui",Plr.PlayerGui) gui.IgnoreGuiInset = true gui.Name = "NearDeathGUI" gui.ResetOnSpawn = false local vignette = Instance.new("ImageLabel",gui) vignette.Size = UDim2.fromOffset(workspace.CurrentCamera.ViewportSize.X,workspace.CurrentCamera.ViewportSize.Y) vignette.Image = "http://www.roblox.com/asset/?id=6301559916" vignette.BackgroundTransparency = 1 vignette.ImageTransparency = 1 vignette.AnchorPoint = Vector2.new(.5,.5) vignette.Position = UDim2.fromScale(.5,.5) repeat wait() until Plr.Character local percent = Plr.Character.Humanoid.Health/100 local neardeath = percent*15 local hum = Plr.Character.Humanoid local nearDeath = false hum:GetPropertyChangedSignal("MaxHealth"):Connect(function() print('max health changed, changing the percent.') percent = hum.Health/100 neardeath = percent*15 end) hum:GetPropertyChangedSignal("Health"):Connect(function() print('changed') if hum.Health <= neardeath and nearDeath == false then nearDeath = true print('near death') TS:Create(L.NearDeathEffect,TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,0),{Brightness = -.3, Saturation = -1}):Play() TS:Create(Plr.PlayerGui.NearDeathGUI.ImageLabel,TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,0),{ImageTransparency = 0}):Play() elseif hum.Health > neardeath and nearDeath == true then nearDeath = false print('regened out') TS:Create(L.NearDeathEffect,TweenInfo.new(2,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0),{Brightness = 0, Saturation = 0}):Play() TS:Create(Plr.PlayerGui.NearDeathGUI.ImageLabel,TweenInfo.new(2,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0),{ImageTransparency = 1}):Play() end end) hum.Died:Connect(function() print('died') TS:Create(L.NearDeathEffect,TweenInfo.new(3,Enum.EasingStyle.Cubic,Enum.EasingDirection.In,0,false,0),{Brightness = -1}):Play() wait(game:GetService("Players").RespawnTime+1) nearDeath = false TS:Create(L.NearDeathEffect,TweenInfo.new(2,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,0),{Brightness = 0, Saturation = 0}):Play() TS:Create(Plr.PlayerGui.NearDeathGUI.ImageLabel,TweenInfo.new(2,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0),{ImageTransparency = 1}):Play() end)
The problem is that it only fires the event once the original humanoid dies. Everytime a character respawns, a new humanoid and character is created.
You should be able to just place the script in StarterCharacterScripts
to fix the issue.