How to vanish players from your game?

Hello everyone! This is going to be a tutorial on how you can vanish players, not making them invisible; but COMPLETELY disappearing them! This tutorial will be both on text and video if you guys want. I will link the video at the end.

This tutorial will be containing 2 parts, one will be preparing the server side (sending the request to vanish the player) and the client side(which will vanish the player) and this all would be operated on a remote event and fired through a chat command. You can implement this on a GUI but i wanted to make it a chat command.

PART 1: SERVER
We start off by creating a script in ServerScriptStorage. Pretty simple
But before that, since this is going to completely operate on a remove event we are going to create it now
Create a remove event in replicated storage and call it "vanishEvent"

Now, I am going to create a table to contain the players that have permission to run the command
This is so that everyone can’t vanish from the game and only people with permission can.
I’m going to call the table “whitelist”

local whitelist = {}

If you want to add your name, just put a string with your name
I’m going to put my name and Player1 just to demonstrate.

local whitelist = {"changeno", "Player1"}

You can add more if you want.

Now let’s get into making a playeradded listener when they join the game! This is going to check if they have permission and store it in a variable(may not be the best option, but it works)

Start off by creating a playeradded event, you know how it goes.

game.Players.PlayerAdded:Connect(function(player)
    local playerWhitelisted = false
end

I put a variable there called “playerWhitelisted” so we can check if the player is whitelisted or not.
Now, we are going to loop through the table until one of the table elements match the player’s name. If so, we will set the variable to true otherwise, we will not do anything.

game.Players.PlayerAdded:Connect(function(player)
    local playerWhitelisted = false
    for _, v in pairs(whitelist) do
        if v == player.Name then
            playerWhitelisted = true
            break
        end
    end
end)

Perfect! We now know if the player is whitelisted or not.
Next, we are going to create a player.Chatted event so we detect when the player chats and check if they wrote the command and they have permission
if they have permission, we are going to loop through every player in the game (except for the player that is going to vanish, if we destroy the player object from the vanishing player it will kick them from the game, thats why I didn’t use FireAllClient) and destroy the vanishing player’s character and player object.
(put the code after the for loop ends)

player.Chatted:Connect(function(message, recipient)
    if message == "/vanish" and playerWhitelisted then -- you can change the command to anything you want, i prefer /vanish
        for _, v in pairs(game.Players:GetPlayers()) do
            if v.Name ~= player.Name then -- checking if the player is the vanishing player. if so, we don't fire the event for them
                game:GetService("ReplicatedStorage").vanishEvent:FireClient(v, player) -- the first parameter is the player thats going to vanis the player from their client and the second one is the player thats going to get vanished
            end
        end
    end
end)

And done! The server part is complete.
Your overall script should look like this:

local whitelist = {yourname}

game.Players.PlayerAdded:Connect(function(player)
    local playerWhitelisted = false
    for _, v in pairs(whitelist) do
        if v == player.Name then
            playerWhitelisted = true
            break
        end
    end
    player.Chatted:Connect(function(message, recipient)
        if message == "/vanish" and playerWhitelisted then
            for _, v in pairs(game.Players:GetPlayers()) do
                if v.Name ~= player.Name then
                    game:GetService("ReplicatedStorage").vanishEvent:FireClient(v, player) 
                end
            end
        end
    end)
end)

PART 2: CLIENT
Now the server part is over, lets get to the client side
From the client side, we are just going to destroy the character and player object of the vanishing player. Not really complicated.

Start off by creating a LocalScript inside of StarterGui

Now, we are going to index the event inside of a variable we had in ReplicatedStorage so we can easily access it

local event = game:GetService("ReplicatedStorage").vanishEvent

After that, create a listener so we can know when the event gets fired.

event.OnClientEvent:Connect(function(playerVanishing)

end)

Perfect! Now we are going to index the character with the player name from workspace and delete it, then destroy the playerVanishing parameter (playerVanshing is the player object of the vanishing player)

event.OnClientEvent:Connect(function(playerVanishing)
    workspace[playerVanishing.Name]:Destroy()
    playerVanishing:Destroy()
end)

Done!!! Your overall script should look like this:

local event = game:GetService("ReplicatedStorage").vanishEvent

event.OnClientEvent:Connect(function(playerVanishing)
    workspace[playerVanishing.Name]:Destroy()
    playerVanishing:Destroy()
end)

PART 3: TESTING
Congrats! You made it this far! Now let’s get to the testing
Now I don’t have any short videos of me testing but the video tutorial at the end tests the script and shows it.

Thank you for reading my tutorial. If you didn’t understand a part, or there are errors with your code, let me know.

CODE LIMITATIONS: So the player vanishes from the game but if they respawn, their character is visible and the players can still see the chat messages of the vanished player.

So hey, a weird comment but I actually don’t know why you would use this other than moderation purposes so yeah.

Video link: How to vanish people from your game in Roblox - YouTube

If you also want to make an unvanish command:

10 Likes

hey, thanks for this tutorial! i really liked it! :smiley:

1 Like

No problem, if you have any questions, let me know :slight_smile:

3 Likes

Heres the unvanish command :grinning_face_with_smiling_eyes:
(Server script ofc)

player.Chatted:Connect(function(msg)
     if msg == "/unvanish" and playerWhitelisted then
         local playerPos = player.Character:GetPrimaryPartCFrame()
         if playerPos then
              player:LoadCharacter()
              player.Character:SetPrimaryPartCFrame(playerPos)
         end
     end
end)

This will load their character then TP them back to their old position.

2 Likes

Really good. I was thinking maybe making the player rejoin would work but this is better

The only way to fully unvanish a player is to have them rejoin, otherwise they won’t reappear on the playerlist since their Player object had been destroyed on the clients of other players.

2 Likes

Why not use table.find?


Also, on another note, your code doesn’t account for players who join the server after the /vanish command has been run, meaning that they will still see the vanished player.

1 Like

I have a refined version of it as a command in an admin system (:incognito <player>) and use it sometimes for spooking people.

I actually kind of browsed for a function like that, seems like I wasn’t careful enough
I suppose you can make the player object reappear if you have a custom leaderboard but still wont show up on the menu

You’re kinda right about the players joining later, I suppose I also need to run the function again when a player joins if someone is vanished.

1 Like

Please don’t loop through a table to find a player in the table, instead

if table.find(whitelist,player.Name) then

Also there’s no reason to handle player vanishing in the client, just do it in server

1 Like

The player will get kicked if the player object is destroyed from the server

The player won’t get “kicked” I tried it it didn’t kick me

Weird, I got kicked when I tried. But I think its better to destroy from the client so the player can still interact with the game.

No, because the client can modify the code so they can vanish without whitelist perms

maybe you destroyed the player instance, not the workspace

1 Like

Ah. I see. I will try to find a way around this. Thanks for letting me know!

1 Like

Irrelevant; only they themselves would see the effects.

they can still modify the local code so it anyways makes them vanish without the remote firing

They can always do that, it isn’t a problem for us and the effects as I’ve mentioned are only visible to them since they’re just calling :Destroy() on the player object (this doesn’t replicate to other clients).

So in this case his vanishing code wouldn’t work? As you said it wouldn’t replicate to all players

It would work, just not be considered “secure” from exploiters since they can disable vanishing on their end by removing the localscript for handling vanishing, thus seeing the vanished player regardless.