Player.CharacterAdded not working in certain script

So right now, I am dealing with a very annoying but that I feel shouldn’t even be happening. in 2 different scripts I am detecting when a player is added, then detecting when the player’s character is added through the exact same code, being:

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		--stuff
	end)
end)

Except in one of the scripts it is only detecting when the character is added about a third of the time for seemingly no reason. The other script works perfectly fine with no problems ever.

Some other details are that the working script has just a few more lines of script that come before the part that detects the player being added and their character (these being a couple of variables), and I have CharacterAutoLoads disabled.

how and where are you loading the player? where did you place this script?

I was loading the player in the version of the script that was working correctly. Both scripts were placed in ServerScriptService.

im pretty sure you have code wrapped inside of player.characteradded, show?

Here is the WORKING script which loads the players character and detects when the player is added.

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.Parent = workspace.Players
	end)
	Player:LoadCharacter()
end)

why are you using :LoadCharacter?

If you have a script like this in ServerScriptService:

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.Parent = workspace.Players
	end)
	Player:LoadCharacter()
end)

And another script like this in ServerScriptService too:

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		warn("did fired", Character)
	end)
end)

Have in mind that upon player join, and while one of the scripts is listening that join, the other one is forcing the character to disappear and spawn again forcing the CharacterAdded to fire twice, or fail.

You can even cause a bug by using 2 scripts like that in which you will end with duplicated models: lol


Im just wondering why you do :LoadCharacter() after the character spawned

I’m using load character because I don’t want players to respawn upon death, meaning that I had to make a custom respawn script. They will respawn at some point eventually when the round ends but for now if you die, you are dead forever. So I’m pretty much just trying to control when the player respawns.

Also just to clear some things up, I only have the Player:LoadCharacter in one of the scripts not in both, so it shouldn’t cause them to spawn double.

So I managed to fix this problem by only having once script detect when the player is added and then firing an event that communicates the player and the character to the other script once they are both added, basically telling the other script when the player and character were added like the functions.

I still am not sure why one script worked 100% of the time and the other one worked like a third of the time. After doing some other testing and making another script that detect when the player and character are added, it was still the one script that always detected and the other 2 either would both detect it or neither would detect it. Roblox studio hurts my brain.

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