Errors in Roblox Player but not in Roblox Studio

Simple, I made a code to determine the player’s speed and health when the player’s character appeared:

local char = player:WaitForChild("Character")
	local hum = char:WaitForChild("Humanoid") 
	hum.WalkSpeed = plrData.Speed
	hum.MaxHealth = plrData.Defense
	hum.Health = plrData.Defense
	print(plrData.Speed)
	print(plrData.Defense)

As you can see, I made the script wait for the player character to then wait for the humanoid and thus modify its speed and life, in the studio everything seems fine without any errors but in Roblox player an error appears saying: “Infinite yield possible on 'Players.Uoshaal:WaitForChild(“Character”)” in the Roblox Player Console

One explanation I found on the forum was that Roblox Player has high ping, Roblox Studio doesn’t, but I still don’t know how to solve the problem.

Edit: Sometimes it appears in the studio but only the blue line that indicates where the error is

Waiting for Answers…

1 Like

player.Character is a property of player not an Instance under it, therefore player:WaitForChild("Character") or player:FindFirstChild("Character") wont work because those methods specifically look for instances under said instance.

Instead you must do:

local character = player.Character or player.CharacterAdded:Wait()