Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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
0
I dont know much about scripting but it doesnt look like its looping, you may need to figure out how to loop it. GottaHaveAFunTime 218 — 6y
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. XAXA 1569 — 6y
0
@XAXA I don't understand, that's the exact reason humanoid = player.Character:WaitForChild("Humanoid") , to always wait for the new humanoid JoeRaptor 72 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago
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...

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
Log in to vote
0
Answered by
sad_eyez 162
6 years ago

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

Answer this question