CharacterAdded not firing for some reason

i have a problem that when i load into the game, anything after the “CharacterAdded” event doesnt fire, as shown in the screenshots but i tried checking if the character does exist before the characteradded event and it says it does exist, do you guys know why by any chance??? ( oh yeah by the way all of this is for walking sounds)
image

if not game:IsLoaded() then
	game.Loaded:Wait()
end


print("game loaded")

local char = game.Players.LocalPlayer.Character
if char then 
	print("character exists")--this does print on the output when joining
end

game.Players.LocalPlayer.CharacterAdded:Connect(function(char)--anything after this line doesnt fire for some reason
	print("char loaded")
	
	local walkingsounds = game.SoundService.walkingsounds:GetChildren()
	
	for i, sounds in walkingsounds do
		local clonesounds = sounds:Clone()
		clonesounds.Parent = char["Right Leg"]
	end
	
	while task.wait(0.1) do
		print("e")
		local humanoid = char:FindFirstChild("Humanoid")
		local root = char:FindFirstChild("HumanoidRootPart")
		local rayOrigin = char.Torso.Position
		local rayDirection = Vector3.new(0,-5,0)

		local rayParams = RaycastParams.new()
		rayParams.FilterType = Enum.RaycastFilterType.Exclude
		rayParams.FilterDescendantsInstances = {
			workspace.Baseplate,
			char:GetDescendants()
		}

		if humanoid.MoveDirection.Magnitude > 0 and root.Velocity.Magnitude > 0.2  then
			local rayResult = workspace:Raycast(rayOrigin,rayDirection,rayParams)

			if not rayResult or rayResult == nil then  continue end

			if rayResult then
				if rayResult.Instance:HasTag("Grass") then
					local grassSFX = char["Right Leg"].grass
					print("grass")
					task.wait(0.1)
					grassSFX:Play()
				elseif rayResult.Instance:HasTag("Wood") then
					print("wood")
				elseif rayResult.Instance:HasTag("Water") then
					print("water")
				elseif rayResult.Instance:HasTag("Metal") then
					print("metal")
				elseif rayResult.Instance:HasTag("Stone") then
					local stoneSFX = char["Right Leg"].stone
					task.wait(0.1)
					stoneSFX:Play()
					print("stone")

				end
			end
		end

	end

end)

Well that’s probably because your character also loads while game is being loaded. Since you are running a wait function before the event, that makes the thing.

If you are planning on making walking sounds, you should use StarterCharacterScripts. The script will be inside of the character, so you have what you need.

oh yeah its in characterscripts, i tried removing the game loading too but it didnt work

If the script is in the StarterCharacterScripts, there’s no reason to track if characteradded or not. Your character is script.Parent

I mean this line:

game.Players.LocalPlayer.CharacterAdded:Connect(function(char)

1 Like

alright, it worked now! tysmmmmmm

1 Like

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