Player.CharacterAdded not working

I want this to print after the player gains a character (disabled by default), but it just doesnt detect it

local Services = require(game:GetService("ReplicatedFirst").Modules.ServicesModule)
local SpawnModule = require(Services.ReplicatedFirst.Modules.MenuSpawnModule)
local LightingModule = require(Services.ReplicatedFirst.Modules.MenuLightingModule)
local CameraModule = require(Services.ReplicatedFirst.Modules.MenuCameraModule)

local Player: Player? = Services.Players.LocalPlayer

Services.Workspace.ChildAdded:Connect(function(child: Instance) 
	if child:HasTag("Map") then
		task.wait()
		child:Destroy()
	end
end)

SpawnModule:SpawnMenu(Services.ReplicatedFirst.MenuObjects)

local CharRig: Model = Services.Workspace.MenuObjects.R6
local CharRigHum = CharRig:FindFirstChildOfClass("Humanoid")

task.defer(function()
	CharRigHum:ApplyDescription(Services.Players:GetHumanoidDescriptionFromUserId(Player.UserId))
end)

task.defer(function()
	CharRigHum:FindFirstChildOfClass("Animator"):LoadAnimation(Services.ReplicatedFirst.Animations.Menu.MenuIdle1):Play()
end)

CameraModule:SetupMainCamera(Services.Workspace.CurrentCamera, Services.Workspace.MenuObjects.MenuCamera, Services.Players.LocalPlayer:GetMouse())
LightingModule:SetupPostProcessingEffects(Services.Lighting)
repeat task.wait() until game:IsLoaded()
LightingModule:SetupLighting(Services.Lighting)

local PlayButton: GuiButton = Services.Workspace.MenuObjects.PlayBar.SurfaceGui.PlayButton
local SelectionFrame: ScrollingFrame = Services.Workspace.MenuObjects.Selection.SurfaceGui.ScrollingFrame

local PlayButtonTween = Services.TweenService:Create(
	PlayButton,
	CameraModule.SelectionCameraTweenInfo,
	{Size = UDim2.new(0,0, 0,0)}
)

local SelectionFrameTween = Services.TweenService:Create(
	SelectionFrame,
	CameraModule.SelectionCameraTweenInfo,
	{Size = UDim2.new(1,0, 1,0)}
)

PlayButton.Activated:Connect(function()
	local RotateTween = Services.TweenService:Create(
		CharRigHum.RootPart,
		CameraModule.SelectionCameraTweenInfo,
		{CFrame = CharRigHum.RootPart.CFrame * CFrame.Angles(0, math.rad(-168.75),0)}
	)
	
	task.defer(function()
		PlayButtonTween:Play()
		CameraModule:SetupSelectionCamera(Services.Workspace.CurrentCamera, Services.Workspace.MenuObjects.SelectionCamera, Services.Players.LocalPlayer:GetMouse())
		SelectionFrameTween:Play()
	end)
	
	task.defer(function()
		for Index, AnimationTrack: AnimationTrack in pairs(CharRigHum:FindFirstChildOfClass("Animator"):GetPlayingAnimationTracks()) do
			AnimationTrack:AdjustWeight(0, CameraModule.SelectionCameraTweenInfo.Time)
		end
		CharRigHum:FindFirstChildOfClass("Animator"):LoadAnimation(Services.ReplicatedFirst.Animations.Menu.MenuIdle2):Play(CameraModule.SelectionCameraTweenInfo.Time/2)
	end)
	
	task.defer(function()
		RotateTween:Play()
	end)
end)

HoverTweenInfo = TweenInfo.new(
	.75,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out
)

local function CreateHoverTween(Button: GuiButton, Size: UDim2)
	local HoverTween = Services.TweenService:Create(
		Button.HoverFrame,
		HoverTweenInfo,
		{Size = Size}
	)
	return HoverTween
end

PlayButton.MouseEnter:Connect(function(x: number, y: number) 
	CreateHoverTween(PlayButton, UDim2.new(1,0, 0,3)):Play()
end)

PlayButton.MouseLeave:Connect(function(x: number, y: number) 
	CreateHoverTween(PlayButton, UDim2.new(0,0, 0,3)):Play()
end)

for Index, Button in pairs(SelectionFrame:GetChildren()) do
	if Button:IsA("GuiButton") then
		Button.Activated:Connect(function()
			local Class = Button:GetAttribute("Class")
			Services.ReplicatedStorage.Remotes.LoadCharacterRemote:FireServer(Class)
			SpawnModule:DestroyMenu(Services.Workspace.MenuObjects)
			LightingModule:DestroyPostProcessingEffects(Services.Lighting)
			LightingModule:RevertLighting(Services.Lighting)
			Services.Workspace.CurrentCamera.CameraSubject = Player.Character
			CameraModule:CeaseCamera(Services.Workspace.CurrentCamera)
			
			for Index, Variable in pairs(Services.ReplicatedFirst:GetChildren()) do
				Variable:Destroy()
			end
		end)
		
		Button.MouseEnter:Connect(function(x: number, y: number) 
			CreateHoverTween(Button, UDim2.new(1,0, 0,1)):Play()
		end)
		
		Button.MouseLeave:Connect(function(x: number, y: number) 
			CreateHoverTween(Button, UDim2.new(0,0, 0,1)):Play()
		end)
	end
end

Player.CharacterAdded:Connect(function(character: Model) 
	print("added")
end)
2 Likes

Hey, I looked at your script — it seems like the reason the CharacterAdded event isn’t firing is probably because the character already exists before that line runs. The event only triggers on new character spawns, not the one that’s already there.
To fix it, you should both connect to the CharacterAdded event and check if Player.Character already exists. Here’s what you can use:

Player.CharacterAdded:Connect(function(character)
	print("Character added:", character.Name)
end)

if Player.Character then
	print("Character already exists:", Player.Character.Name)
end

Also double-check that this is in a LocalScript, not a ServerScript. LocalPlayer won’t work in a server script — it’ll be nil, and then none of the character stuff will work.
And if you’re using CharacterAutoLoads = false somewhere, you need to manually call Player:LoadCharacter()to spawn it. Hope this helps!

1 Like

It didnt work

  1. It’s a Script with RunContext on Client
  2. Player:LoadCharacter() is called from a ServerScript with a remote
1 Like

Might be loading the character before your script runs — CharacterAdded only works if it connects before the character loads. Just add a check for Player.Character too, like:

Player.CharacterAdded:Connect(function(char)
	print("added")
end)

if Player.Character then
	print("already added")
end
1 Like

i did, also i found a workaround by just firing a remote back to the client from the afformentioned ServerScript

1 Like

That’s great! So is this solved? Let me know if you still need help.

just realized I kinda sound like AI

1 Like

yeah you do, and it’s solved for what i need to do