local Plrs = game.Players:GetPlayers() local PlrChar = Plrs.Character local PlrTorso = PlrChar:WaitForChild("Torso")
I alredy defined "Character" but it keeps saying that is nil!
I've tried it in two ways, changing from normal script to local script [and changing his parent, to ServerScriptService, or ReplicatedFirst] but the error is the same!
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') -- incase the torso is nil 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
Your problem is that you are trying the get the Character from a list of players. You must first either loop through the players and get their characters that way or you should choose the particular player you want to affect. Hope this helps and have a great day scripting! Edit: if you want to affect all the players just loop through them like so:
local playersService = game:GetService("Players")-- get service is the recommended way of getting the players service local players = playersService:GetPlayers() for i, player in pairs(players) do -- for each player do the following code local char = player.Character -- and so on you get the idea end
Hope this helps!
local Plrs = game.Players:GetChildren() local PlrChar = Plrs.Character local PlrTorso = PlrChar:WaitForChild("Torso")
Not sure if this is going to work or not but i don't really know what you're trying to ask and accomplish here.