CharacterAdded refuses to fire

Maybe I am just missing something very simple, but unless i remove everything and only keep the plr variable and the CharacterAdded function with the print statement, the CharacterAdded function does not fire

Local Script inside StarterPlayerScripts
local plr = game.Players.LocalPlayer
local deadGui = plr.PlayerGui:WaitForChild("DeadGUI")
local background = deadGui:WaitForChild("Background")
local deadText = background:WaitForChild("DeadText")
local reboot = background:WaitForChild("Reboot")
local txt = reboot.TextLabel
local TS = game:GetService("TweenService")
local TSinfo = TweenInfo.new(0.6,Enum.EasingStyle.Quart,Enum.EasingDirection.Out)
local flatline = background.DeathFlatline
local boom = background.DeathBoom
local camera = game.Workspace.CurrentCamera
print("hi")

plr.CharacterAdded:Connect(function(char)
	print("spawned")
	local Humanoid = char:WaitForChild("Humanoid")
	boom:Stop()
	flatline:Stop()
	camera.CameraType = Enum.CameraType.Custom
	background.Visible = false
	Humanoid.Died:Connect(function()
		print("dead")
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = CFrame.new(1000,1000,1000)
		boom:Play()
		flatline:Play()
		background.Visible = true
		flashtext()
		deadText:TweenSize(UDim2.new(1, 0,0.4, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Back,0.6)
		task.wait(2)
		TS:Create(txt,TSinfo,{TextTransparency = 0})
		TS:Create(txt.Glow,TSinfo,{ImageTransparency = 0.8})
		dotdotdot()
	end)
end)

I wont include the functions since them being included in the script and not does not affect it at all

Does it even get to plr.CharacterAdded part?

it prints the “hi” i added after the variables, no errors, not sure?

try checking the character : Player.Character if its loaded bcuz it does not fire once the character is loaded already so you will need to separate that function

character seems to be nil, strange, what do you suggest i do?
i have other scripts with CharacterAdded that just work so i am incredibly confused

What do you mean? Do you mean that CharacterAdded returns you nil? Also is your script inside of StarterPlayer.StarterPlayerScripts

CharacterAdded doesn’t return anything, it doesn’t fire

Edit: Yes the script is in starterplayer

Please read my post, i have already done that and it would print “spawned”

Oh, okay, sorry. Maybe try doing plr.Character? if it does not give the character parameter.

as i said the characteradded doesnt fire once the character is loaded so you will need to check if the character is already loaded to run the function

local plr = game.Players.LocalPlayer
local deadGui = plr.PlayerGui:WaitForChild("DeadGUI")
local background = deadGui:WaitForChild("Background")
local deadText = background:WaitForChild("DeadText")
local reboot = background:WaitForChild("Reboot")
local txt = reboot.TextLabel
local TS = game:GetService("TweenService")
local TSinfo = TweenInfo.new(0.6,Enum.EasingStyle.Quart,Enum.EasingDirection.Out)
local flatline = background.DeathFlatline
local boom = background.DeathBoom
local camera = game.Workspace.CurrentCamera
print("hi")

local function OnCharacterAdded(Character) 
	print("spawned")
	local Humanoid = char:WaitForChild("Humanoid")
	boom:Stop()
	flatline:Stop()
	camera.CameraType = Enum.CameraType.Custom
	background.Visible = false
	Humanoid.Died:Connect(function()
		print("dead")
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = CFrame.new(1000,1000,1000)
		boom:Play()
		flatline:Play()
		background.Visible = true
		flashtext()
		deadText:TweenSize(UDim2.new(1, 0,0.4, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Back,0.6)
		task.wait(2)
		TS:Create(txt,TSinfo,{TextTransparency = 0})
		TS:Create(txt.Glow,TSinfo,{ImageTransparency = 0.8})
		dotdotdot()
	end)
end

plr.CharacterAdded:Connect(OnCharacterAdded)

if plr.Character then
	OnCharacterAdded(plr.Character)
end

I think I know your issue, the character loads in before the function is connected. Possibly because of the WaitForChild Stuff that is above the code. Maybe try this?

local plr = game.Players.LocalPlayer

plr.CharacterAdded:Connect(function(char)
	print("spawned")
	
	local deadGui = plr.PlayerGui:WaitForChild("DeadGUI")
	local background = deadGui:WaitForChild("Background")
	local deadText = background:WaitForChild("DeadText")
	local reboot = background:WaitForChild("Reboot")
	local txt = reboot.TextLabel
	local TS = game:GetService("TweenService")
	local TSinfo = TweenInfo.new(0.6,Enum.EasingStyle.Quart,Enum.EasingDirection.Out)
	local flatline = background.DeathFlatline
	local boom = background.DeathBoom
	local camera = game.Workspace.CurrentCamera
	
	local Humanoid = char:WaitForChild("Humanoid")
	boom:Stop()
	flatline:Stop()
	camera.CameraType = Enum.CameraType.Custom
	background.Visible = false
	Humanoid.Died:Connect(function()
		print("dead")
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = CFrame.new(1000,1000,1000)
		boom:Play()
		flatline:Play()
		background.Visible = true
		flashtext()
		deadText:TweenSize(UDim2.new(1, 0,0.4, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Back,0.6)
		task.wait(2)
		TS:Create(txt,TSinfo,{TextTransparency = 0})
		TS:Create(txt.Glow,TSinfo,{ImageTransparency = 0.8})
		dotdotdot()
	end)
end)
1 Like

This seems to have resolved my issue, though I am still mildly confused on how none of my other scripts have this issue, thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.