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

How do you address all players in-game?

Asked by 10 years ago

That title was probably confusing but like, can you say "game.Players.Player"? or something like that? Sorry, I'm new to scripting.

Like, for example, all the torsos of all the players on a server to change transparency. How would I address the players/player in the script?

2 answers

Log in to vote
1
Answered by
User#2 0
10 years ago

You would use a for loop for this.

for i,v in pairs(game.Players:GetPlayers()) do
    print(v.Name)
end

That would print the name of all the player's in game. If you notice, though, there's one special peice of code here.

for i,v in pairs(game.Players:GetPlayers()) do

What this does is says "for each player inside of game.Players, do"

So you have Player objects, not player's characters yet. Getting a player's character is easy, though. Player's have a Character property! We just set the player's character's torso's Transparency property to 1, as you would in the properties panel!

v.Character.Torso.Transparency = 1

If we put this all together we get this:

for i,v in pairs(game.Players:GetPlayers()) do
    v.Character.Torso.Transparency = 1
end
0
Thank you! OfficialAndrew 45 — 10y
Ad
Log in to vote
-1
Answered by
bloxxyz 274 Moderation Voter
10 years ago

I'm not really an advanced scripter myself, but I THINK I know what you mean.

Instead of having to write game.Players.InsertNameHere.Torso.Transparency = 0.5 , you want this to apply to all players, and I'm guessing you want this to happen the second the player appears?

You would simply do the following:

game.Players.PlayerAdded:connect(function() 
game.Players.Torso.Transparency = 0.5

end)

Now of course, the script above would probably not work for your case scenario, but what happens is when a Player is added, everyone's Torso Transparency is 0.5, experiment with it a little, hopefully this helped a little.

0
Thank you, it did. OfficialAndrew 45 — 10y
0
Can you give me an upvote? Glad to help. bloxxyz 274 — 10y

Answer this question