I am making a script in which it needs to find the players and the character and interacts with both. I know how to find all the players in the game as you can see but I don't know how to find all the characters(where the torso and stuff is)
game.Players.PlayerAdded:connect(function(Player) game.Players.PlayerAdded:connect(function(plr) plr.Chatted:connect(function(chat) if chat == "SPromo" then if plr:GetRankInGroup(2651783) >= 13 then if then end end end end) end) end)
I need it to find all the players in the final if then section
To obtain any given player's character, use the Character property of the Player object. So, for instance, to get the torso in your function, you could do:
local torso = plr.Character.Torso
I will fix your script and answer your question.
game.Players.PlayerAdded:connect(function(Player) game.Players.PlayerAdded:connect(function(plr) plr.Chatted:connect(function(chat) if chat == "SPromo" then if plr:GetRankInGroup(2651783) >= 13 then if then end end end end) end) end)
this is the wrong way to do this, as you have two of the same function it is not needed you can use the same function to use the chat and players.
game.Players.PlayerAdded:connect(function(plr) plr.Chatted:connect(function(msg) if msg == "SPromo" then if plr:GetRankInGroup(2651783) >= 13 then if then end end end end) end)
that is the correct way to do your script, you can still use the "plr" portion as well as the "msg" portion.
now, to get the players torso or whatever part you need you should do this,
local torso = plr.Character:findFirstChild("Torso")
that is just the way I do it, now here is another way to do it
local torso = plr.Character.Torso
I hope I helped!