I attempted testing out a part that would get a player's Character with :FindFirstChild(). Here's the script:
script.Parent.Touched:Connect(function(part) local parent = part.Parent local plr = game.Players:GetPlayerFromCharacter(parent) if parent and plr then local char = plr:FindFirstChild("Character") end end)
However, "char" returns a nil value. Why is this the case?
Hi,
You can use plr.Character. Contrarily to popular belief, Character is a property of the player object, not a child. That said, you cannot use the FindFirstChild() method.
In the event that your code runs before the Character is present, you can use the CharacterAdded event as follows:
char = plr.Character or plr.CharacterAdded:wait()
For your code, however, you should be set by simply putting:
char = plr.Character