Why isn't my characterAdded event firing?

None of these print statements are firing and I have no idea why:

game.Players.PlayerAdded:Connect(function(player) -- Fires whenever a player joins the game
	
	local success, owned = pcall(MarketPlaceService.UserOwnsGamePassAsync, MarketPlaceService, player.UserId, 98681915) -- Checks if player owns the "2X kills gamepass", pcall just means it keeps calling it until its successful

	if success and owned then -- Sets an attirbute to true if they own it, I check if this attritbute is true in my killHandler script and if it is I give +2 kills instead of +1
		player:SetAttribute("GamepassOwned", true)
	elseif not success then
		player:Kick("Failed to retrieve gamepass data. Please rejoin!")
	else
		player:SetAttribute("GamepassOwned", false)
	end
	
	player:SetAttribute("Kills", 0)
	player:SetAttribute("Deaths", 0)
	
	player:GetAttributeChangedSignal("InGame"):Connect(function() -- If the value changes this function is called
		updateResetButton:FireClient(player) -- Fires the client to disable/enable the reset button based on the value
	end)
	
	player:SetAttribute("InGame", false) -- The reason I set it to false and then true is because if i just set it to false straight away, the value changed function wouldn't be called, so I set it to true then false so its called when a player first joins the game too
	
    -- THIS IS WHAT ISN'T WORKING
	player.CharacterAdded:Connect(function()
		print("Char Added")
		if player:GetAttribute("InGame") == false then
			print("Called :)")
			local winstreakGuiClone = winstreakGui:Clone()
			winstreakGuiClone.Parent = workspace[player.Name].Head
			if player.leaderstats:FindFirstChild("Winstreak").Value == 0 then
				print("0 Winstreak)")
				winstreakGuiClone.Enabled = false
			else
				winstreakGuiClone.Enabled = true
			end
		end
	end)

I thought i’d keep the code above the characterAdded event in incase it had something to do with it. Thanks for any help :slight_smile:

you might be connecting the event after the players character already loaded, try joining the game and resetting ur character, then it should print, to fix this you can just add

local character = player.Character or player.CharacterAdded:Wait()

in the first line of the playeradded event, then do all your stuff that you do in the characteradded function outside of it too

1 Like

Do it the other way round, I remember having a similiar bug a long time ago.

1 Like

Thank you both for your help, the function is getting called now, only issue is its saying that “rafferty05” is not in the workspace, even though it is. Any ideas why?

Could you show your updated code, and what line you are getting the error on?

game.Players.PlayerAdded:Connect(function(player) -- Fires whenever a player joins the game
	
	player:GetAttributeChangedSignal("InGame"):Connect(function() -- If the value changes this function is called
		updateResetButton:FireClient(player) -- Fires the client to disable/enable the reset button based on the value
	end)

	player:SetAttribute("InGame", false) -- The reason I set it to false and then true is because if i just set it to false straight away, the value changed function wouldn't be called, so I set it to true then false so its called when a player first joins the game too
	
	player.CharacterAdded:Connect(function()
		print("Char Added")
		if player:GetAttribute("InGame") == false then
			print("Called :)")
			local winstreakGuiClone = winstreakGui:Clone()
			winstreakGuiClone.Parent = workspace:FindFirstChild(player.Name).Head
			if player.leaderstats:FindFirstChild("Winstreak").Value == 0 then
				print("0 Winstreak)")
				winstreakGuiClone.Enabled = false
			else
				winstreakGuiClone.Enabled = true
			end
		end
	end)

Output:

’ Char Added - Server - LobbyHandler:27
15:38:30.294 Called - Server - LobbyHandler:29
15:38:30.294 ServerScriptService.LobbyHandler:31: attempt to index nil with ‘Head’

CharacterAdded event provides a character argument, change
player.CharacterAdded:Connect(function()
to
player.CharacterAdded:Connect(function(char)
and instead of doing workspace:FindFirstChild(player.Name), you can just do char.Head

1 Like

Working perfectly, thank the both of you very much for your help :slight_smile:

1 Like

No problem. Good luck on your game or whatever you’re doing :smile:

1 Like

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