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

How do I make other players besides me invisible?

Asked by 4 years ago
Edited 4 years ago

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!

1 answer

Log in to vote
0
Answered by
IDKBlox 349 Moderation Voter
4 years ago

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
  1. All you're doing is getting the Children of the character which that only gets the main body parts and the accessories themselves. In order for that to work, you'd need to get their children aswell
if Child:IsA('Accessory') then
    Child.Transparency = 1
end
  1. Accessories do not have a transparency themselves... Just their BasePart children within it.
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 :)

0
Hello, thanks for your contribution! I really appreciate your time! anyway, I am having trouble on why it makes all players invisible when I am only trying to make the clients character the only one visible, what i am trying to say is to the player, everyone else is invisible except for them, I am sorry if your answer solves this but I am being dumb and if that is the case one more [p1] BigChildren 77 — 4y
0
push in the right direction would be honestly really great, these comments aren't doing me much justice lol so if you want you could message me on discord if not that is still fine. Thank you! BigChildren 77 — 4y
0
Alright, I'm still a little confused on exactly what you're wanting lol. But yeah I'll add you on discord and we can chat there IDKBlox 349 — 4y
Ad

Answer this question