Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you address all players in-game?

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

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

1 comment

0

Thank you!

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.

2 comments

0

Thank you, it did.

0

Can you give me an upvote? Glad to help.

This discussion is preserved as it was. New answers, comments, and votes are closed.