CharacterAdded event not firing

I want this remote event ForcePlayerIntoSeat whenever a character resets, so they can’t jump around. I’m using a CharacterAdded event to do this, but it is for some reason not firing. I have put print statements inside the event to see if the problem is in the remote event, but my output is empty.

for _, player in game:GetService("Players"):GetPlayers() do	
	player.CharacterAdded:Connect(function(character)
		
		print("CharacterAdded event fired")
		game.ReplicatedStorage.ForcePlayerIntoSeat:FireServer(character)
	end)
end

It’s not firing because when your script runs, players:GetPlayers() is empty. Thus, the event is added to nothing.
I would assume you wanted to connect the event to every player that joins? In that case you should use players.PlayerAdded:Connect()

Hello, the problem is that the script will only work for players who joined before the script runs.
Instead, you should use this:

local Players = game:GetService("Players")

function PlayerAdded(player: Player)
	player.CharacterAdded:Connect(function(character)
		print("CharacterAdded event fired")
		game.ReplicatedStorage.ForcePlayerIntoSeat:FireServer(character)
	end)
end

Players.PlayerAdded:Connect(PlayerAdded)

-- For people that were already here before script run
for _, player in Players:GetPlayers() do
	task.spawn(PlayerAdded, player)
end

Thanks, this works now! Just wondering, what does task.spawn do?

task.spawn runs a function without waiting for it to complete, allowing the rest of the script to continue. In any case, it’s very rare to have early joiners (players who join before the script runs).

1 Like