So I have this working piece of code here that will get the player’s character from the workspace but I don’t know if it’s efficient to do this or not:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local plrChar = game.Workspace:WaitForChild(tostring(plr))
print(plrChar)
print(plrChar.Parent)
end)
The piece of code that I have shown above is the best way that I know to get the player’s character from the server.
Can someone tell me if there are better and efficient ways to get the player character from the server?
Alright so I have made changes to that piece of code and used that method but when I try to print the character’s Parent property it is always nil, can you please explain to me why that happens?
Here’s the changes that I have made:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local plrChar = plr.Character or plr.CharacterAdded:wait()
print(plrChar)
print(plrChar.Parent)
end)
Here’s a screenshot of what it’s printing in the output: