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

Death effect only works the first time I die?

Asked by
Axenori 124
4 years ago

I've recently made a death effect, it a local script located inside StarterPlayerScripts and applies a ColorCorrectionEffect and Blur to the screen upon death. It works perfectly fine when for the first time I die, but after I die once it simply doesn't activate, any idea why?

Code:

local CCE = Instance.new("ColorCorrectionEffect", game.Lighting)
CCE.Saturation = 0
CCE.Brightness = 0
CCE.Contrast = 0
local BE = Instance.new("BlurEffect", game.Lighting)
BE.Size = 0
script.Parent.Parent.CharacterAdded:Wait()
script.Parent.Parent.Character:WaitForChild("Humanoid").Died:Connect(function()
    for i = 1, 150 do
wait(0.0125)
BE.Size = BE.Size + 0.45
CCE.Saturation = CCE.Saturation - 0.0125
CCE.Brightness = CCE.Brightness - 0.00625
CCE.Contrast = CCE.Contrast - 0.00625
    end
    wait(0.5)
for i = 1, 75 do
wait(0.0125)
BE.Size = BE.Size - 0.9
CCE.Saturation = CCE.Saturation + 0.025
CCE.Brightness = CCE.Brightness + 0.0125
CCE.Contrast = CCE.Contrast + 0.0125
    end
    CCE.Saturation = 0
CCE.Brightness = 0
    CCE.Contrast = 0
    BE.Size = 0
    end)
0
What is wrong with your code is on line 07. When a character is added it fires a wait. You need to add :Connect because all you are telling it to do is wait. There is a disconnect between when the player is added and when the player dies. I will post a simpler code so you get what I mean. LudeonDev 50 — 4y
0
~~~~~~~~~~~~~~~~~ script.Parent.Parent.CharacterAdded:Connect(function(player) print("I spawned") script.Parent.Parent.Character:WaitForChild("Humanoid").Died:Connect(function() print("I died") end) end) ~~~~~~~~~~~~~~~~~ LudeonDev 50 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago
local CCE = Instance.new("ColorCorrectionEffect", game.Lighting)
CCE.Saturation = 0
CCE.Brightness = 0
CCE.Contrast = 0
local BE = Instance.new("BlurEffect", game.Lighting)

BE.Size = 0

script.Parent.Parent.CharacterAdded:Connect(function(player)
    print("i entered")
    script.Parent.Parent.Character:WaitForChild("Humanoid").Died:Connect(function()
        print("I died")
        for i = 1, 150 do
    wait(0.0125)
    BE.Size = BE.Size + 0.45
    CCE.Saturation = CCE.Saturation - 0.0125
    CCE.Brightness = CCE.Brightness - 0.00625
    CCE.Contrast = CCE.Contrast - 0.00625
        end
        wait(0.5)
    for i = 1, 75 do
    wait(0.0125)
    BE.Size = BE.Size - 0.9
    CCE.Saturation = CCE.Saturation + 0.025
    CCE.Brightness = CCE.Brightness + 0.0125
    CCE.Contrast = CCE.Contrast + 0.0125
        end
        CCE.Saturation = 0
    CCE.Brightness = 0
        CCE.Contrast = 0
        BE.Size = 0
    end)

Here is the fundamental idea:

script.Parent.Parent.CharacterAdded:Connect(function(player)
    print("I spawned")
    script.Parent.Parent.Character:WaitForChild("Humanoid").Died:Connect(function()
        print("I died")
    end)
end)

Good scripting

0
Sorry, this is my first time using scriptinghelpers. LudeonDev 50 — 4y
0
please upvote me, if this works. LudeonDev 50 — 4y
0
the "player" parameter is basically the character since the event's name. on line 11 just use player:WaitForChild("Humanoid") or you can modify player to char so it's understandable. anything else should work fine bluzorro 417 — 4y
0
bluzorro I get what you mean. It is just a habit of mine always filling in the parameters. You are right you do not need the player parameter but the script works 100% Thank you for the criticism. LudeonDev 50 — 4y
0
Thanks! Axenori 124 — 4y
Ad

Answer this question