Death screen GUI won't fade out properly

Hi, I’m trying to make a death GUI where after the GUI shows, it later fades away. Something like Dark souls’ death screen.

Though, the problem is it won’t work nor give the output any errors when I try to make the GUI fade away. Some reason the color correction effect works but not my GUI.

I’ve tried adding a wait function to let the GUI fade in, then later fade out. I also tried not using a module function and making a table for the fade out function on the same script. None of these worked though.

Here is an example of the effect I want to achieve

0:01-0:02 is what I am trying to replicate

(Note: This is my first post, so I apologize for any mistakes I may have not noticed during writing this)

GUI Script:

local Player = game:GetService("Players").LocalPlayer
local Players = game:GetService("Players").PlayerAdded


Players:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character:WaitForChild("Humanoid").Died:Connect(function()
			local PlayerGUI = Player.PlayerGui
			PlayerGUI:WaitForChild("DeathScreenGUI").Enabled = true
			
			local DeathModule = require(game:GetService("ReplicatedStorage"):WaitForChild("DeathModuleScript"))
			
			local DeathBackground = PlayerGUI:WaitForChild("DeathScreenGUI").DeathBackground
			DeathModule.DBGFunction1(DeathBackground)
			
			local DeathTitle = PlayerGUI:WaitForChild("DeathScreenGUI").DeathTitle
			DeathModule.DTFunction1(DeathTitle)
			
			wait(1)
			
			DeathModule.DTFunction2(DeathBackground)
			DeathModule.DBGFunction2(DeathTitle)
			
			local DeathColor = Instance.new("ColorCorrectionEffect",game.Lighting)
			DeathModule.DCFunction1(DeathColor)
			wait(9)
			DeathModule.DCFunction2(DeathColor)
		end)
	end)
end)

Module Script:

local DeathModule = {}

local TweenService = game:GetService("TweenService")

DeathModule.DBGFunction1 = function(DBGObject)
	local DBGInfo = TweenInfo.new(0.6, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 1)
	local DBGGoal = {ImageTransparency = 0.3}
	local DBGTween = TweenService:Create(DBGObject, DBGInfo, DBGGoal)
	DBGTween:Play()
	return DBGTween
end

DeathModule.DTFunction1 = function(DTObject)
	local DTinfo = TweenInfo.new(0.8, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 1)
	local GTGoal = {ImageTransparency = 0, Size = UDim2.new(0.2, 230, 0.1, 30), Position = UDim2.new(0.3, 10, 0.5, -32)}
	local GTTween = TweenService:Create(DTObject, DTinfo, GTGoal)
	GTTween:Play()
	return GTTween
end

DeathModule.DBGFunction2 = function(DBGObject)
	local DBGInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 1)
	local DBGGoal = {ImageTransparency = 1}
	local DBGTween = TweenService:Create(DBGObject, DBGInfo, DBGGoal)
	DBGTween:Play()
	return DBGTween
end

DeathModule.DTFunction2 = function(DTObject)
	local DTinfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 1)
	local GTGoal = {ImageTransparency = 1}
	local GTTween = TweenService:Create(DTObject, DTinfo, GTGoal)
	GTTween:Play()
	return GTTween
end

DeathModule.DCFunction1 = function(DCObject)
	local DCinfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 1)
	local DCGoal = {Brightness = -0.3, Contrast = -0.3, Saturation = -1}
	local DCTween = TweenService:Create(DCObject, DCinfo, DCGoal)
	DCTween:Play()
	return DCTween
end

DeathModule.DCFunction2 = function(DCObject)
	local DCinfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 1)
	local DCGoal = {Brightness = 0, Contrast = 0, Saturation = 0}
	local DCTween = TweenService:Create(DCObject, DCinfo, DCGoal)
	DCTween:Play()
	return DCTween
end

return DeathModule

Is it possible you could show us a video as to what your GUI currently looks like?

Updated it. Should I show more in the video or is that enough to see?

I’m trying to recreate this on my studio right now…

Just for clarification, where is your GUI script located in the explorer and what type of script is it (LocalScript or just Script)?

Sorry if the quality is bad, both GUI are image labels and located in the StarterGui. The GUI script is located in the server script service while the module script is in replicated storage.

Where is the Djobject variable I can’t seem to find it (found out that its in the bracket mb)

I’m not sure if you can tween a player’s UI via a script I’m pretty sure you need to use a localscript. Correct me if I am wrong. I would make the script fire a remoteEvent when the player dies that goes to a localscript and makes the tween.

I made it a normal script because for some reason Humanoid.Died doesn’t work for local script. Also when I tween the UI the first function worked but the second didn’t. I could remove the second function and it would work fine. Also I’m still new to scripting and started a few days ago with prior knowledge. I haven’t tried remote event. I’ll try to learn about it.

1 Like

Yeah that’s why you should use a remote event. What you do is you make it so when the humanoid.Died function does it it fires a remote event to a local script. And then it makes the tween there. You should go search and learn about remoteEvents they are very useful :+1:

I will make the script and send it to you. Make sure to learn from it :wink:

1 Like

Should that be marked as the solution then? Also I’m guessing remoteEvents are kinda like ModuleScripts as they are not in one whole script. Correct me if I’m wrong. I’m gonna start researching RemoteEvents now.

1 Like

If you feel like it should be the solution then you can!! I didn’t do much so I won’t mind it if you don’t feel like giving it. I will make the script just so you get an Idea on how remoteEvents work make sure to go search about them since they are extremely useful :+1:

Alright then, I’ll mark it as the solution once you are done with the script.

Did you maybe think about trying to just put a LocalScript inside the screen gui and define the varaibles like so:

local Player = game.Players.LocalPlayer
local Humanoid = Player.Character:WaitForChild("Humanoid")

local DeathModule = require(game:GetService("ReplicatedStorage").DeathModuleScript)

Humanoid.Died:Connect(function()
    local DeathBackground = script.Parent.DeathBackground
    local DeathTitle = script.Parent.DeathTitle

    DeathModule.DBGFunction1(DeathBackground)
    DeathModule.DTFunction1(DeathTitle)
    	
    wait(1)
    DeathModule.DTFunction2(DeathBackground)
    DeathModule.DBGFunction2(DeathTitle)
    	
    local DeathColor = Instance.new("ColorCorrectionEffect",game.Lighting)
    DeathModule.DCFunction1(DeathColor)
    	
    wait(9)
    	
    DeathModule.DCFunction2(DeathColor)
end)

@Dev_Simphony told me I could use a remote event but I’ll try doing local script in ScreenGui to see if it helps.

2 Likes

It doesn’t work. I tried enabling player GUI but it plays like the original script.

Here is everything!! It looks pretty clean and I hope you like it. You can copy the code I did in this video.

Thanks, by any chance could you copy and paste it? You don’t have to. Just wondering so I could save time lol.

1 Like

Yeah sure.

Script:



game:GetService('Players').PlayerAdded:Connect(function(player)
	function playerDied()
		local humanoid = player.Character.Humanoid
		print(player.Character)
		local remote = game.ReplicatedStorage.remoteEvent
		remote:FireClient(player)
	end
	
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			print(player.Name .. " has died!")
			playerDied()
		end)
	end)
	
end)

Local Script :

local remoteEvent = game.ReplicatedStorage.remoteEvent
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer

remoteEvent.OnClientEvent:Connect(function()
	print(player)
	local mainFrame = player.PlayerGui.ScreenGui.mainFrame
	local text = player.PlayerGui.ScreenGui.mainFrame.TextFrame
	mainFrame.Visible = true
	text.Visible = true
	local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
	local mainFrameTween = TweenService:Create(mainFrame, tweenInfo, {BackgroundTransparency = 1})
	local Text2FrameTween = TweenService:Create(text, tweenInfo, {TextTransparency = 1})
	local TextFrameTween = TweenService:Create(text, tweenInfo, {TextSize = 100})
	TextFrameTween:Play()
	TextFrameTween.Completed:Wait()
	mainFrameTween:Play()
	Text2FrameTween:Play()
end)
2 Likes