Player.CharacterAdded:Wait() not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I’m attempting to have this script set the players clothing after they died, so I’m trying to wait for their character to load first, then set the clothing.

  2. What is the issue?
    The script just stops at the .CharacterAdded:Wait() nothing after that will fire.

  3. What solutions have you tried so far?
    I’ve tried moving the script to StarterGui, and looking at similar problems, but to no avail. I’ve tried different things like .CharacterAppearanceLoaded

Extra Details:
The script is a LocalScript
The script is currently in StarterCharacterScripts.

player = game.Players.LocalPlayer
function setvar()
	department = player.Team
	print(department.Name)
end

function setclothingondeath()
	wait(0.5)
	print("funcstarted")
	if department then
		
		player.CharacterAdded:Wait()
		
		print("depatmentfound")
		game.ReplicatedStorage.Events.CharacterDepartmentChangeServer:FireServer(department)
	end
end

player.Character:WaitForChild("Humanoid").Died:Connect(setclothingondeath)
game.ReplicatedStorage.Events.CharacterOutfitFinalClient.Event:Connect(setvar)
1 Like

It stops because the character is dying so it is being removed from the game along with the script inside the character. The script gets deleted every time a new character is added.

Possible Solution
Put the script in starter player not starter character

1 Like

You are running player.CharacterAdded:Wait() when the character might already be loaded. Simply replace player.CharacterAdded:Wait() with this:

if not player.Character then
player.CharacterAdded:Wait()
end
5 Likes

Works! I just had to make an adjustment for the quicker replication time.

2 Likes