Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Find all players?

Asked by 9 years ago

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

0
I don't know what you are trying to find here however why do you have 2 of the same functions -_- KingLoneCat 2642 — 9y
0
I have 2 of the same functions as 1 controls the chat and the other controls players Conmmander 479 — 9y

2 answers

Log in to vote
3
Answered by 9 years ago

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
Ad
Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
9 years ago

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!

Answer this question