Why my code will not run correctly?

Hello. I made a code, which each time a player dies it will fire a remote I won’t expand because it’s not necessary. Basically, I instanced a ColorCorrectionEffect on the client into the CurrentCamera and changing it’s brightness on a for loop, for some reason, it will just do it half way on the for loop and stop running the rest of the code which is coming right after it.
Here’s my code:

local players = game:GetService("Players");

local localPlayer = players.LocalPlayer;

local character = localPlayer.Character;

local humanoid = character:WaitForChild("Humanoid");

local function on_Death()

local succed, stringError = pcall(function()
	local currentCamera = workspace.CurrentCamera
	local colorCorrectionEffect = Instance.new("ColorCorrectionEffect")
	colorCorrectionEffect.Parent = currentCamera
	colorCorrectionEffect.Saturation = -1
	local remoteEvent = script.Remote;
	for i = 0, 1, 0.01 do
		colorCorrectionEffect.Brightness = i
	for x = 1, 0, -0.01 do
		colorCorrectionEffect.Brightness = x

if succed then
	warn("Succed to run code with no errors.")
	warn("Failed to run code; error: ".. string.lower(tostring(stringError)))



Image of it, the script is the local script:

Is there any error?
ColorCorrectionEffect should be on lighting I think.
wait(0.0001) just doesn’t makes sense since wait() min amount is 1/30
Check output.

Keep in mind for loops are yielding functions which means, it will yield all code below them

1 Like

No. The output is empty (in the matter it doesn’t return anything), I may try right now to do it on a pcall and see what it returns.

Is it a localscript? Where did you place your script? This will help me when finding the problem :smiley:

Okay, there’s many errors now I realize, so first off, how are you retreiving from server the Event insie a local script?

It’s a local script that I typed it on.

I put it on a pcall, it doesn’t return anything.

how are you retreiving from server the Event insie a local script?

Where is the script placed?

The script is placed under StarterGui.

1 Like
	for x = 0, 1, -0.01 do
		colorCorrectionEffect.Brightness = x

This is not gonna work.
You’re doing - when start is at 0
and end at 1
it should be

for x = 0, 1, 0.01 do
1 Like

I fixed this out, but it still doesn’t work.
Do you see any other error?

Can you elaborate what the script is supposed to do? It will help me.

1 Like

Never mind! I found a solution already.

I already found the solution, thank you for trying to help though! :slight_smile:

Would you mind sharing the solution, and marking it as such? I guarantee someone else will ask the same thing later, you may be able to help them.

1 Like

Yes, I am sharing the solution rn.

Basically, the loop ran a half because the Player has reloaded after he reseted his Character, so the Script stopped since it’s a LocalScript and it’s under StarterGui that means it’s being replicated straight into the player’s PlayerGui. And PlayerGui is under the Player and because the Player is reloading it’s reloading as well and all the objects inside of it. So, to fix that, you’d just have to make sure the time it takes for the loops to finish is lower than the amount of time for the Player and Character to reload.

1 Like