Hello, I am wondering how would I go about making other players besides me go invisible until I press the 'Deploy' button I have in my game. Basically, make the players spawn transparent so I wouldn't have to clone a new spawn as this would be easier in my opinion. Here is my code:
game.Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) for i,Child in pairs(Character:GetChildren()) do if Child:IsA('Part') or Child:IsA('MeshPart') then Child.Transparency = 1 end end for i,Child in pairs(Character:GetChildren()) do if Child:IsA('Accessory') then Child.Transparency = 1 end end Character.Head.face.Transparency = 1 end) end)
In this code, it makes me go invisible and I am aware of why but my problem is making players other than me invisible because that's all I need and I am refraining from destroying accessory but if it is needed for the script to work then that is also fine. Thank you for reading! p.s. if needing more info, my discord is Child#3611 or just write a comment on this post, whatever you prefer!
Alright, let me explain what you're having a problem with, there are a couple
for i,Child in pairs(Character:GetChildren()) do if Child:IsA('Part') or Child:IsA('MeshPart') then Child.Transparency = 1 end end
if Child:IsA('Accessory') then Child.Transparency = 1 end
local Players = game:GetService('Players') local function InvisibleCharacter(Character) for i,child in pairs (Character:GetDescendants()) do if child:IsA('BasePart') or child:IsA('Decal') then --child.LocalTransparencyModifier = child.Transparency local a = Instance.new('NumberValue') a.Value = child.Transparency a.Name = 'ItemTransparency' a.Parent = child child.Transparency = 1 end end print(Character.Name,'Is now invisible') end local function VisibleCharacter(Character) for _,child in pairs (Character:GetDescendants()) do local originalTransparency = child:FindFirstChild('ItemTransparency') if originalTransparency then child.Transparency = originalTransparency.Value originalTransparency:Destroy() end end print(Character.Name,'Is now visible') end local function CharacterAdded(Character) wait() InvisibleCharacter(Character) end Players.PlayerAdded:Connect(function(Player) if Player.Character then CharacterAdded(Player.Character) end Player.CharacterAdded:Connect(CharacterAdded) end)
Alright, what I have done here is set it up for you.. I want you to learn from this... so
What this does is it gets their character whenever it's added and gets the Descendants of Character(Checking if it's a basepart or Decal) and saves all of it's current transparency under a number value named 'ItemTransparency' which we call back later when we want to revert the process(Making the character visible again)
you make the character Invisible by calling function InvisibleCharacter() -- with the argument being the player.Character
you make the character Visible again by calling function VisibleCharacter() -- again with the argument being the player.Character
All the Visible function does is loops through the descendants like before, but instead of checking if it's a basepart or not, it goes through looking for that 'ItemTransparency' Number value we added in before and set the part/decals transparency back to what it previously was set to.
If you still have any questions, feel free to ask! Hope this helps :)