LocalPlayer.Character sometimes never shows up on mobile

Hey. Got a bizarre issue here. Here’s a block of code that runs during a loading screen, right before we anchor their character and send them to a main menu:

if not game.Players.LocalPlayer.Character then
    game.Players.LocalPlayer.CharacterAdded:Wait()
end

On most desktops, and many mobile devices, this works just fine. However, on some (including my Pixel 10), this yields forever. What’s interesting is that a “Infinite yield possible” warning is never thrown.
We tried to debug this a little

if not game.Players.LocalPlayer.Character then
		warn("Can't find player's character")
		local iterations = 0
		while not game.Players.LocalPlayer:FindFirstChild("Character") do
			task.wait(0.5)
			iterations += 1
			GUI.LoadingScreen.TextLabel.Text = "Initializing Menu - Waiting for character... (" .. iterations .. ")" 
		end
end

This just goes forever on my mobile device. A fellow dev using a Pixel 6 is able to get in just fine.

Anyone know why this happens and how to fix it?

Character isnt child of local player so it will never appear, Character is a property of the Player instance so LocalPlayer.Character is the correct approach, not LocalPlayer:FindFirstChild(“Character”)

Okay, but that doesn’t solve the first issue, where it never does appear.

Mobile runs slower than Pc, thats why in pc the

if not game.Players.LocalPlayer.Character then

never occurs, but for mobile it does and the problem is that you’re putting

		while not game.Players.LocalPlayer:FindFirstChild("Character") do

instead of:

while not game.Players.LocalPlayer.Character do

Okay so with the second method, it appears to be working. So why won’t it work with the first method? Is it possible that the if statement evaluates to false, but the PlayerAdded signal is getting fired before the code starts waiting for it, thus it just sits there forever?

that, or its just roblox problem because i used to use that first method before aswell but its not reliable so i switch to just while loop like the 2nd method plus it wont take so much computing resources because you only loops it for brief moment before the character loads

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