✓ Accepted answer
I'm pretty sure this was what you were trying to do:
game:GetService("Players").PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild('Torso')
end)
Put this script inside a folder, preferably in the "ServerScriptService". Your code is returning character as nil, because character is not a property or child of :GetPlayers(). Which returns an array of all the players in the server. A second method of doing this, would be using "in pairs" which is shown on the :GetPlayers() wiki itself:
https://wiki.roblox.com/index.php?title=API:Class/Players/GetPlayers
for _,v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Character then
local character = v.Character
local torso = character:WaitForChild('Torso')
end
end
3 comments
.Character is not a property of tables.
ok then loop through the players and affect them one by one
I edited my answer to better help you. If it answers your question please accept. Otherwise comment how I can help you better.