For some reason only works on the players first death, and I have no idea how to fix this!
fade = script.Parent fadeGoal = 0 fadeRate = 0.01 function updateFade() local current = fade.BackgroundTransparency if current < fadeGoal then fade.BackgroundTransparency = math.min(fadeGoal,current+fadeRate) elseif current > fadeGoal then fade.BackgroundTransparency = math.max(fadeGoal,current-fadeRate) else fade.BackgroundTransparency = fadeGoal end end player = game.Players.LocalPlayer character = player.Character or player.CharacterAdded:wait() humanoid = player.Character:WaitForChild("Humanoid") rs = game:GetService("RunService") fadeGoal = 1 humanoid.Died:connect(function () wait(1) fadeGoal = 0 player.CharacterAdded:wait() fadeGoal = 1 end) rs.RenderStepped:connect(updateFade) fade.Visible = true
while wait() do fade = script.Parent fadeGoal = 0 fadeRate = 0.01 function updateFade() local current = fade.BackgroundTransparency if current < fadeGoal then fade.BackgroundTransparency = math.min(fadeGoal,current+fadeRate) elseif current > fadeGoal then fade.BackgroundTransparency = math.max(fadeGoal,current-fadeRate) else fade.BackgroundTransparency = fadeGoal end end player = game.Players.LocalPlayer character = player.Character or player.CharacterAdded:wait() humanoid = player.Character:WaitForChild("Humanoid") rs = game:GetService("RunService") fadeGoal = 1 humanoid.Died:connect(function () wait(1) fadeGoal = 0 player.CharacterAdded:wait() fadeGoal = 1 end) rs.RenderStepped:connect(updateFade) fade.Visible = true end
did you try adding a loop? this should work...
I don't know if this would work, but you maybe could update what humanoid we are listening to, as XAXA said.
fade = script.Parent fadeGoal = 0 fadeRate = 0.01 function updateFade() local current = fade.BackgroundTransparency if current < fadeGoal then fade.BackgroundTransparency = math.min(fadeGoal,current+fadeRate) elseif current > fadeGoal then fade.BackgroundTransparency = math.max(fadeGoal,current-fadeRate) else fade.BackgroundTransparency = fadeGoal end end player = game.Players.LocalPlayer character = player.Character or player.CharacterAdded:wait() humanoid = player.Character:WaitForChild("Humanoid") rs = game:GetService("RunService") fadeGoal = 1 function newhumanoid() humanoid.Died:connect(function () wait(1) fadeGoal = 0 player.CharacterAdded:wait() fadeGoal = 1 newhumanoid() end) end rs.RenderStepped:connect(updateFade) fade.Visible = true
Otherwise, if this did not work, we could just reset the script.
fade = script.Parent fadeGoal = 0 fadeRate = 0.01 function updateFade() local current = fade.BackgroundTransparency if current < fadeGoal then fade.BackgroundTransparency = math.min(fadeGoal,current+fadeRate) elseif current > fadeGoal then fade.BackgroundTransparency = math.max(fadeGoal,current-fadeRate) else fade.BackgroundTransparency = fadeGoal end end player = game.Players.LocalPlayer character = player.Character or player.CharacterAdded:wait() humanoid = player.Character:WaitForChild("Humanoid") rs = game:GetService("RunService") fadeGoal = 1 humanoid.Died:connect(function () wait(1) fadeGoal = 0 player.CharacterAdded:wait() fadeGoal = 1 script:Clone().Parent = script.Parent script:Destroy() end) rs.RenderStepped:connect(updateFade) fade.Visible = true
Here is how I did it if it helps:
First Add a RemoteEvent to ReplicatedStorage Called "DiedEvent"
Add this script to "ServerScriptService"
local died = game:GetService("ReplicatedStorage")["DiedEvent"] game.Players.PlayerAdded:Connect(function(plr) game.Players.CharacterAutoLoads = true plr.CharacterAdded:Connect(function(char) local human = char:WaitForChild("Humanoid") human.Died:Connect(function() died:FireClient(plr) end) end) end)
Add this localscript inside the frame that you want to fade
local died = game:GetService("ReplicatedStorage")["DiedEvent"] died.OnClientEvent:Connect(function(plr) local plr = game.Players.LocalPlayer game.Players.CharacterAutoLoads = false for i = 10,0,-1 do wait(0.05) script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency - 0.1 end wait() plr:LoadCharacter() for i = 10,0,-1 do wait(0.05) script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency + 0.1 end end)
I hope this helped :)