Make Blocked Users Invisible

Dear Devforum members, I been trying to make this code work for the entire day, yet I seriously still cant. I really need all the help I can get and I will begin explaining my big wild day of coding today.

So, the issue in this code I made is that whenever a new player joins that is blocked. The code doesnt make them invisible for some reason. However it works perfectly when I block them or unblock them in the game.

Please help me out here.

and this is the current code so far

BlockedUserIds = game:GetService("StarterGui"):GetCore("GetBlockedUserIds")
playerBlockedEvent = game:GetService("StarterGui"):GetCore("PlayerBlockedEvent")
playerUnBlockedEvent=game:GetService("StarterGui"):GetCore("PlayerUnblockedEvent")


game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
    for i,v in pairs(game.Players:GetChildren()) do    
        if table.find(BlockedUserIds,v.UserId) then
            Invisibilazor(v)
        end
    end
end)



game.Players.PlayerAdded:Connect(function(player)
    for i,v in pairs(game.Players:GetChildren()) do
        if table.find(BlockedUserIds,v.UserId) then
            Invisibilazor(v)
        end
    end
end)

if playerBlockedEvent then
    playerBlockedEvent.Event:Connect(function(player)
        Invisibilazor(player)
    end)
end
if playerUnBlockedEvent then
    playerUnBlockedEvent.Event:Connect(function(player)
        visibilazor(player)
    end)
end


function Invisibilazor(player)

    if player.Character then
        for i, part in ipairs(player.Character:GetDescendants()) do
            if (part:IsA("BasePart") or part:IsA("Decal")) and part.Name ~= "HumanoidRootPart" then
                part.Transparency = 1


            end
        end
    else
        player.CharacterAdded:Wait()
        for i, part in ipairs(player.Character:GetDescendants()) do
            if (part:IsA("BasePart") or part:IsA("Decal")) and part.Name ~= "HumanoidRootPart" then
                part.Transparency = 1


            end
        end
    end


end
function visibilazor(player)

    if player.Character then
        for i, part in ipairs(player.Character:GetDescendants()) do
            if (part:IsA("BasePart") or part:IsA("Decal")) and part.Name ~= "HumanoidRootPart" then
                part.Transparency = 0


            end
        end
    else
        player.CharacterAdded:Wait()
        for i, part in ipairs(player.Character:GetDescendants()) do
            if (part:IsA("BasePart") or part:IsA("Decal")) and part.Name ~= "HumanoidRootPart" then
                part.Transparency = 0


            end
        end
    end


end

Wait, I’m confused… game.Players.PlayerAdded only works on the server script but here game.Players.LocalPlayer your referencing the localplayer but that only works on the client script? Unless I’m having the biggest brain fart

It also works on client.


The first issue I’ve noticed is the script not using CharacterAdded for blocked players, except the user himself for some reason? I also dont understand why you loop through players when someone joins instead of the new player? It might not get parented in time I think.

Ah I see * Up until recently, this event didn’t work on the client (in Localscripts), but this has been changed - Guess its an update they made.

BlockedUserIds = game:GetService("StarterGui"):GetCore("GetBlockedUserIds")
playerBlockedEvent = game:GetService("StarterGui"):GetCore("PlayerBlockedEvent")
playerUnBlockedEvent=game:GetService("StarterGui"):GetCore("PlayerUnblockedEvent")
function Visual(Player, Transparency)
 if player.Character then
        for i, part in (player.Character:GetDescendants()) do
            if (part:IsA("BasePart") or part:IsA("Decal")) and part.Name ~= "HumanoidRootPart" then
                part.Transparency = Transparency


            end
        end
    else
        player.CharacterAdded:Wait()
        for i, part in (player.Character:GetDescendants()) do
            if (part:IsA("BasePart") or part:IsA("Decal")) and part.Name ~= "HumanoidRootPart" then
                part.Transparency = Transparency


            end
        end
    end
end
function blockplayersinvisible(player)
   task.wait(1)
   if table.find(BlockedUserIds,player.UserId) then
      Visual(player,1)
   end
end
game.Players.LocalPlayer.CharacterAdded:Connect(blockplayersinvisible(game.Players:GetPlayerFromCharacter(Character)))
game.Players.PlayerAdded:Connect(blockplayersinvisible(player))

if playerBlockedEvent then
    playerBlockedEvent.Event:Connect(function(player)
       Visual(player,1)
    end)
end
if playerUnBlockedEvent then
    playerUnBlockedEvent.Event:Connect(function(player)
       Visual(player,0)
    end)
end
task.wait(2)
for i,v in (game.Players:GetChildren()) do    
    if table.find(BlockedUserIds,v.UserId) then
         Visual(v,1)
    end
end

Alright, so basically all I did was clean up the code, added a wait before we get the table, made it so were not looping through ever player when a new player joins, and then at the end of the code I added a loop that checks again and make sure that everyone is invisible.

1 Like

Thanks friend, I will try this out now. I will let you know if it works or not.

I had to tweek it a bit but this works. Thank you once again and here is your green checkmark.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.