Cant get player character

Hi, I’m trying to get the player’s character so I can check for some factors. However, I can’t seem to get the player’s character despite the argument being valid; in which plr contains the player’s name (mine in this context). What is the issue?

ServerScript:

local function Checker(plr)
.
.
.
if plr then
		local player = game.Players:FindFirstChild(tostring(plr))
		local character = player:WaitForChild("Character") -- Infinite yield possible on 'Players.tz_ow:WaitForChild("Character")' 
		if character then
			if character:FindFirstChild("Tray") then
				Count = Count + #character:FindFirstChild("Tray").Foods:GetChildren()
			else
			end
		end
	end

ServerScript2:

.
.
.

RunService.Heartbeat:Connect(function()
	task.wait(PetStats.pickupspeed)
	local value = CheckIfAvailable:Invoke(Player)
.
.
.

Character is not a child of Player, it’s actually a property that points to the player’s character within the workspace.

repeat
     task.wait()
until player.Character

This snippet waits until the character actually exists.

thank you, much appreciated. this was it

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