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

Death effect only works the first time I die?

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)

2 comments

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.

0

1 answer

✓ Accepted answer
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

5 comments

0

Sorry, this is my first time using scriptinghelpers.

0

please upvote me, if this works.

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

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.

0

Thanks!

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