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: