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

How to hide all players on your screen and only your screen using a textButton?

Asked by 4 years ago

The application of this button would be for hiding other players on your screen in a parkour game. Other players could potentially be playing the same level as you and therefore be in your screen view. You should be able to toggle whether other players are visible on your screen or not.

I have a screen GUI with a frame inside and a textButton inside the frame. The local script is located inside of the textButton.

local hideButton = script.Parent.Parent.HidePlayers
local Players = game:GetService("Players")
local plr = game.Players.LocalPlayer

repeat wait() until plr.Character
local chr = plr.Character
local hum = chr:WaitForChild("Humanoid")

function hideOrShowOthers()

    if hideButton.Text == "Hide Players" then
        hideButton.Text = "Show Players"
        for i, v in pairs(game.Workspace:GetDescendants()) do
            if v:IsA("Humanoid") then
                if plr.Name ~= v.Name then
                    v.Humanoid.LocalTransparencyModifier = 1    
                else
                    v.Humanoid.LocalTransparencyModifier = 0    
                end
            end 
        end
    end

    if hideButton.Text == "Show Players" then
        hideButton.Text = "Hide Players"
        for i, v in pairs(game.Workspace:GetDescendants()) do
            if v:IsA("Humanoid") then
                if plr.Name ~= v.Name then
                    v.Humanoid.LocalTransparencyModifier = 0    
                else
                    v.Humanoid.LocalTransparencyModifier = 0    
                end
            end 
        end
    end

end

hideButton.MouseButton1Click:Connect(hideOrShowOthers)

My biggest issue so far is understanding what to loop through and how to loop through all the currently connected players and get their humanoids, so that I can use LocalTransparencyModifier to change their transparency. If my Idea is wrong, I would appreciate corrections on why I wouldn't be able to do so.

Also, if my code is not good enough to understand the concept, I would appreciate hints on how I could go about completing it. I am not looking for someone to do all the work for me but instead would like to use this question as a way to help me learn how my concept is wrong and how I can improve on the concept I have given in order to eventually complete it.

So, how I would be able to manipulate the transparency of every player connected to the game on a button click, so that they are invisible to you and only you until you click the button again? Keep in mind that your player must always be visible and the character visibility changes should only happen on your own screen so that other players can use the button for the same purpose (of making other players not visible on your screen).

I am quite new to Roblox Studio, so I would appreciate any explanations about why my thought process might be wrong and how to improve my problem-solving skills in Roblox.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

you can just set every player to a transparency of 1, also making every singe part in them transparent, then would still be bale to be collided with but you can do that easily, theres articles on how to make players non collidable with eachother. anyways, its simple, find every player, then locate to their chaarcters, then set all of the parts in all the chaarcters to transparency = 1, use a pairs loop like this:

for _,i in pairs(game.Players:GetChildren()) do--this gets every single player in the game

    wait()
        for _,ii in pairs(i.Character:GetDescendants()) do--get every part in the player without multiple loops

            if ii.ClassName == "Part" or ii.ClassName == "Decal" then

                if not ii.Name == "HumanoidRootPart" then

                    ii.Transparency = 1
                end     


            end

        end

end

(Fixed the script)

Edit: and when making them visible again, ignore the humanoidroot part like this, also i spaced it out a bit i like doing that when scripting):

for _,i in pairs(game.Players:GetChildren()) do--this gets every single player in the game

    wait()
        for _,ii in pairs(i.Character:GetDescendants()) do--get every part in the player without multiple loops

            if ii.ClassName == "Part" or ii.ClassName == "Decal" then

                if not ii.Name == "HumanoidRootPart" then

                    ii.Transparency = 0
                end     


            end

        end

end

that should work. It loops through every player, and for every player, it loops through all the parts in it's character, and to avoid scripts and stuff like that, it checks to see if the child being tested is a part, then makes it transparent / invisible.

hope this helps :3 <3

0
also there might be hats with parts in them, so do the same thing just create another lop that checks inside accessories inside each charactor, and then make the handle of the accessory transparent too :) AlexanderYar 788 — 4y
0
also if you dont want your character to be invisible, just check for the name of each player, if its the name of your character, then make it not loop through it. AlexanderYar 788 — 4y
0
also, player collision is already turned off in my game alivemaeonman 14 — 4y
0
BRUH, JUST PUT THIS IN A LOCAL SCRIPT, USE REMOTE EVENT TO ACTIVATE LOCALSCRIPT FROM THR SERVER SIDE BUTTON. and also i commented how to not make yourself invisible, just check if the player being tested is game.PLayers.LocalPlayer since its localscript, if it ism then dont run it, then it wil continue to all other players AlexanderYar 788 — 4y
View all comments (6 more)
0
one question why would i be using transparency and not local transparency modifier alivemaeonman 14 — 4y
0
ok then just use local transpareny modifier, i script using old methods but you dont have to. I see no extra work in adding one remove event and then calling it and receiving  it and then just using transparency. They both work. Also, dont use many loops like i said its actually more efficient to just use GetDescendants() of the character that way it will get every part no matter where it is in th AlexanderYar 788 — 4y
0
Ill try that out using your old method and test it. Thanks! alivemaeonman 14 — 4y
0
I've got it to work but the players face is still visible. what can i do to make sure the face is invisible as well? alivemaeonman 14 — 4y
0
also, when i press the button to show the players again, i see a gray torso inside of my torso. how would i fix that? alivemaeonman 14 — 4y
0
ok so the grey thing, as you may know, is the humanoid root part, just put in a line of code to always ignore it, and for the face, put in an extra line to also always change its transparency. Give me a minute ill change the code to do that. Also, we could use pcall here to make everything transparent that can be, but its not worth it, just add two extra lines and it will do. by the way it looks l AlexanderYar 788 — 4y
Ad

Answer this question