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

[Filtering Enabled] Hide Other Players. Any help?

Asked by 9 years ago

In this script there are 3 simple things that are suppose to happen. If your on :

1player.PlayerService.PlayerTeam.Value = BrickColor.new"White"

then all other players are completely invisible.

If you are on:

1player.PlayerService.PlayerTeam.Value = BrickColor.new"Medium stone grey"

then everyone is completely visible

If you are on:

1player.PlayerService.PlayerTeam.Value = BrickColor.new"Bright red"

Then all other players are transparent and red

I have tested this script in studio with a server of 2 players, it worked in both cases. But when I asked my brother and sister to test it with me the transparency part didn't work, but when the game started one of them turned transparent red. My game is set up very specifically with lots of int values and string values for the players. If you have any questions on why something is the way it is, ill answer that question.

Here is the script:

01local player = game.Players.LocalPlayer
02local char = player.Character
03wait()
04 
05for _, v in pairs(game.Players:GetChildren()) do
06    if v.Name == player.Name then
07        wait()
08    elseif v:IsA'Player' then
09        for p, t in pairs (v.Character:GetChildren()) do
10            if t:IsA'Part' then
11                t.Transparency = 1
12            elseif t:IsA'Hat' then
13                t.Handle.Transparency = 1
14                v.Head.Face.Transparency = 1
15            end
View all 97 lines...
0
Once a player joins, how quickly does their team color get set? As soon as they join? Programmix 285 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I'm not going to guarantee this, but I think I spotted your issue.

1if t:IsA'Part' then
2t.Transparency = 1
3elseif t:IsA'Hat' then
4t.Handle.Transparency = 1
5v.Head.Face.Transparency = 1
6end

If I recall properly, I'm pretty sure that elseif will nullify if the first condition is correct, but don't quote me on this.

Basically, If the first "If" statement is viable, in this case, if t is a part, then it will run that and end the script, simple as that. However, if it isn't a part, then it will resort to the "elseif" statement, which is to see if t is a hat.

I'm pretty sure this is how if functions work, if I recall properly, but yet again, don't quote me on this.

Also, the correct format of those lines.

01if t:IsA'Part' or t:IsA'Hat' then --this allows both to be checked at the same time
02    if t:IsA'Part' then --if its a part then... (game will skip the function if not viable)
03        t.Transparency = 1
04    end
05 
06    if t:IsA'Hat' then --if its a hat then...
07        t.Handle.Transparency = 1
08        v.Head.Face.Transparency = 1
09    end
10end

The finalized (fixed) script:

001local player = game.Players.LocalPlayer
002local char = player.Character
003wait()
004 
005for _, v in pairs(game.Players:GetChildren()) do
006    if v.Name == player.Name then
007        wait()
008    elseif v:IsA'Player' then
009            for p, t in pairs (v.Character:GetChildren()) do
010            if t:IsA'Part' or t:IsA'Hat' then
011                if t:IsA'Part' then
012                t.Transparency = 1
013            end
014            if t:IsA'Hat' then
015                t.Handle.Transparency = 1
View all 109 lines...

ALSO, line 59 to 78 I might have spotted a similar error, so if it still doesn't work try replacing those lines with the following code:

Original:

01player.PlayerService.PlayerTeam.changed:connect(function(val)
02    wait()
03    if val == BrickColor.new("Bright red") then
04        for _, v in pairs(game.Players:GetChildren()) do
05            if v.Name == player.Name then
06                wait()
07            elseif v:IsA'Player' then
08                for p, t in pairs (v.Character:GetChildren()) do
09                    if t:IsA'Part' then
10                    t.Transparency = 0.75
11                    t.BrickColor = BrickColor.new("Bright red")
12                    elseif t:IsA'Hat' then
13                        t:Destroy()
14                        v.Head.Face.Transparency = 0.75
15                    end
16                end
17            end
18        end
19    end
20end)  

Modified:

01player.PlayerService.PlayerTeam.changed:connect(function(val)
02    wait()
03    if val == BrickColor.new("Bright red") then
04        for _, v in pairs(game.Players:GetChildren()) do
05            if v.Name == player.Name then
06                wait()
07            elseif v:IsA'Player' then
08                for p, t in pairs (v.Character:GetChildren()) do
09                    if t:IsA'Part' or t:IsA'Hat' then
10            if t:IsA'Part' then
11                t.Transparency = 0.75
12                t.BrickColor = BrickColor.new("Bright red")
13            end
14            if t:IsA'Hat' then
15                t:Destroy()
View all 23 lines...

PS: If you want to get the finalized code without all the #'s if you CTRL+C & CTRL+V'd it, just look at the source by highlighting the code and then pressing the button that has the white page and the <> signs.

0
No, is if-and-elseif statements were completely correct. They can never be both a hat and a part. Programmix 285 — 9y
0
I seemed to figure this out myself, but another glitch that makes this not work properly is that when a player resets it doesnt recognize it... So if a player resets and they are suppose to be invisible, they will become uninvisible. CarterTheHippo 120 — 9y
0
2 Other things that have caused a problem, is RootParts and face decals. I simply removed this factors in this script, which fixed the problem and now it works 100%, but i am not happy. When a player is suppose to be invisible i dont want to see the faces, or when i make them visible again I dont want to see a big blue root part. CarterTheHippo 120 — 9y
Ad

Answer this question