p.CharacterAdded Event Not Working

Issues Encountered with p.CharacterAdded


Goal
I am trying to achieve a simple system where when a player approaches a part or walks away, their ExposureCompensation decreases/increases depending on their distance from the part.

Problem Encountered
The issue with this is with the event p.CharacterAdded being fired, however, it appears that this is not occurring. I have added various print statements, and it is apparent that the event is not firing as it should be doing typically. If any of you gave your guidance on how to solve this, that would be greatly appreciated.

Video: https://gyazo.com/ca753fdb82b02b8490f57755e7151bc7
Ignore the indefinite yield on :WaitForChild() issue as it is unrelated

Attempted Solution
I have tried many things in an attempt to solve this issue; however, it appears that it sadly has not resolved itself. I have included things such as p.CharacterAdded:wait() among other things (such as printing to debug) and to try and solve this. At first I thought there was a referencing typo, however, there were zero errors in the console indicating so.

P.S: Two of the print statements actually printed “Test”. The print statements with the red dot beside them are from the script, the others are not relevant to the script. You can view the output below:
image

Here is the code below:

local debounce = false

local plrs = game:GetService("Players")
local rs = game:GetService("RunService")
local tweenservice = game:GetService("TweenService")
local lighting = game:GetService("Lighting")


print(1)
local subtitle = require(game:GetService("StarterPlayer").StarterPlayerScripts.TextHandler)
print('test')
local p = plrs.LocalPlayer
print('test')

print(p)
-----------------------------------------------------------------------------------------------------------------------------
p.CharacterAdded:wait()
p.CharacterAdded:Connect(function()
	print('test')
	rs.Stepped:Connect(function()
		print('test')
		if debounce then return end
			if p.Character then

				local distance = p:DistanceFromCharacter(workspace.Room1008.SCP.Main.Position)
			
			
			    if distance <= 5 and lighting.ExposureCompensation ~= -7 then --If player is in range

					debounce = true
					print("Vision is fading..") -- commented out due to excessive printing with rs.Stepped
		
					local tween = tweenservice:Create(game:GetService("Lighting"), TweenInfo.new(1), {ExposureCompensation = -7})
					tween:Play()
	
				elseif distance <= 30 and lighting.ExposureCompensation ~= 0 then -- If player is outside of active range
				
					debounce = true

					print("Vision is back!") -- commented out due to excessive printing with rs.Stepped

					local tween2 = tweenservice:Create(game:GetService("Lighting"), TweenInfo.new(1), {ExposureCompensation = 0})
					tween2:Play()
				
				elseif distance >= 31 and lighting.ExposureCompensation ~= 0  then
					debounce = true
					local tween = tweenservice:Create(game:GetService("Lighting"), TweenInfo.new(1), {ExposureCompensation = 0})
					tween:Play()
				end
			debounce = false
		end
	end)
end)
print('test')

It appears I have found the issue. It appears that the Character was loading BEFORE the event which was causing nothing to occur. I have fixed the issue with the following:

local Player = game.Players.LocalPlayer

function CharAdded(Character)
--Code here for character
end
if Player.Character then
spawn(function()
CharAdded(Player.Character)
end)
end
game.Players.PlayerAdded:Connect(CharAdded)

Edit: In the future, I believe using this method will probably allow me to avoid this in the future with just the use of an extra function.