I'm trying to get all players and make their head transparency = to 1
1 | for i,v in pairs { game.Players } do |
2 | v.Character.Head.Transparency = 1 |
3 | end |
Like drahsid5 said, you made it a table. However, his script isn't that sufficient(I think that's the proper word, I'm tired ok?). You could replace GetChildren
with GetPlayers
, so if there's something like a Part
in Players
(not sure why there would be), it'd only get the players, you could also replace game.Workspace:WaitForChild(v.Name)
with v.Character
.
Code:
1 | for i, v in pairs (game.Players:GetPlayers()) do |
2 | v.Character:WaitForChild( "Head" ).Transparency = 1 |
3 | end |
Please tell me if it work's, I wasn't able to test it.
Small mistake, you have to make it a table, that's an object.
1 | for i, v in pairs (game.Players:GetChildren()) do |
2 | game.Workspace:WaitForChild(v.Name):WaitForChild( "Head" ).Transparency = 1 |
3 | end |
Alright, you forgot to call the method that will give you all the children inside Players. the most efficient method for that is :GetPlayers(). If you're using it in any other object, use :GetChildren(). The way you did would work for a table.
like:
1 | Table = { "hi" , "bye" } |
2 |
3 | for i,stuff in pairs (Table) do -- See, I didn't use GetChildren() or GetPlayers() here. It's a table. |
4 | print (i,stuff) |
5 | end |
When you use :GetChildren() or GetPlayers(), you're basically turning the content into a table so you can use the loop.
01 | for i,Player in pairs (game.Players:GetPlayers()) do |
02 | if Player.Character then -- Checks if their character exists. It might have been removed for some reason or not spawned yet |
03 | if Player.Character:FindFirstChild( "Head" ) then |
04 | Player.Character.Head.Transparency = 1 |
05 | end |
06 | end |
07 | end |
08 |
09 | -- you can also tune it up and set some variables to save you from writing 'Player.Character.Head' over and over again |
10 |
11 | for i,Player in pairs (game.Players:GetPlayers()) do |
12 | local Char = Player.Character |
13 | if Char then |
14 | local Head = Char:FindFirstChild( "Head" ) |
15 | if Head then |
16 | Head.Transparency = 1 |
17 | end |
18 | end |
19 | end |
1 | for _, v in pairs (game.Players:GetChildren()) do |
2 | if v.Character ~ = nil then |
3 | v.Character.Head.Transparency = 1 |
4 | end |
5 | end |