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;
remoteEvent:FireServer(humanoid)
wait(0.3)
for i = 0, 1, 0.01 do
colorCorrectionEffect.Brightness = i
wait(0.0001)
end
wait(0.4)
for x = 1, 0, -0.01 do
colorCorrectionEffect.Brightness = x
wait(0.0001)
end
end)
if succed then
warn("Succed to run code with no errors.")
else
warn("Failed to run code; error: ".. string.lower(tostring(stringError)))
end
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
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.