I'm trying to get all players and make their head transparency = to 1
for i,v in pairs {game.Players} do v.Character.Head.Transparency = 1 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:
for i, v in pairs(game.Players:GetPlayers()) do v.Character:WaitForChild("Head").Transparency = 1 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.
for i, v in pairs(game.Players:GetChildren()) do game.Workspace:WaitForChild(v.Name):WaitForChild("Head").Transparency = 1 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:
Table = {"hi","bye"} for i,stuff in pairs(Table) do -- See, I didn't use GetChildren() or GetPlayers() here. It's a table. print(i,stuff) end
When you use :GetChildren() or GetPlayers(), you're basically turning the content into a table so you can use the loop.
for i,Player in pairs(game.Players:GetPlayers()) do if Player.Character then -- Checks if their character exists. It might have been removed for some reason or not spawned yet if Player.Character:FindFirstChild("Head") then Player.Character.Head.Transparency = 1 end end end -- you can also tune it up and set some variables to save you from writing 'Player.Character.Head' over and over again for i,Player in pairs(game.Players:GetPlayers()) do local Char = Player.Character if Char then local Head = Char:FindFirstChild("Head") if Head then Head.Transparency = 1 end end end
for _, v in pairs(game.Players:GetChildren()) do if v.Character ~= nil then v.Character.Head.Transparency = 1 end end