Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't characteradded execute?

Title pretty much says it all.

game.Players.PlayerAdded:connect(function(player)	
	createstats(player)
	cloneready(player)
	clonespawned(player)
	clonefirst(player)
	updategui()
	print("Functions executed") -- this does print
	player.CharacterAdded:connect(function(character)
		print("Character added") -- This doesn't print
		logo(player)
		player.PlayerGui.SpawnGui.BG.Visible = true
		character.Humanoid.Died:connect(function()
			died(player)
		end)
	end)
end)

I get no errors in the output. CharacterAdded has been a very finicky thing for me before now and I'd really like to know if I'm just using it wrong.

edit: After doing some more testing in my place, I found out that characteradded fires when the player respawns, but not on the first spawn. I am using a test server rather than play solo, so characteradded should work the first time, but it doesn't...

edit2: I also went to the real place on my profile and played it there. The characteradded function still didn't fire when I spawned, but did after I died.

2 comments

0

Do any of the functions above your CharacterAdded statement yeild (use wait or just stop the script in general somehow?)

0

They do, but I have prints at the end of each function and of of them do print. Everything runs fine until the characteradded function, then it just stops until the player dies for the first time and respawns.

1 answer

The first spawn most likely occurs before you can attach the CharacterAdded event.

The cleanest way to fix this is to make your CharacterAdded a function on its own and simulate that CharacterAdded event right after you attach it.

function NewCharacter(character,player)
	print("Character added") -- This doesn't print
	logo(player)
	player.PlayerGui.SpawnGui.BG.Visible = true
	character.Humanoid.Died:connect(function()
		died(player)
	end)
end

game.Players.PlayerAdded:connect(function(player)   
	createstats(player)
	cloneready(player)
	clonespawned(player)
	clonefirst(player)
	updategui()
	print("Functions executed") -- this does print
	player.CharacterAdded:connect(function(character)
		NewCharacter(character,player);
	end)
	if player.Character then
		-- We were too late getting the
		-- CharacterAdded attached--there already
		-- was a character, so we need to simulate
		-- the event firing here.
		NewCharacter(player.Character,player);
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.