Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Frame Fade in Transparency script on Death only works once?!

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

3 comments

0

I dont know much about scripting but it doesnt look like its looping, you may need to figure out how to loop it.

1

A new humanoid is made every time the player dies. You must listen to CharacterAdded, get the humanoid from that new character, and connect to the humanoid's Died event.

0

@XAXA I don't understand, that's the exact reason humanoid = player.Character:WaitForChild("Humanoid") , to always wait for the new humanoid

3 answers

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 :)

This discussion is preserved as it was. New answers, comments, and votes are closed.