I am new to lua and I wanted to try and make the char a ghost like thing, walk through and invisible, how do I do that?
✓ ANSWER ACCEPTED
How to make character ghost like?
2 answers
✓ Accepted answer
I will help you but from now on you have to only post about actual Scripting problems, that you have, read the guidlines please or you will get shutdown, this is what you need to do
local Player = game:GetService("Players").LocalPlayer --// This gets the localPlayer, this is your Player
local Character = Player.Character or Player.CharacterAdded:wait() --// This gets your Character
game.Players.PlayerAdded:Connect(function() --// This fires when someone eneters the Game
if (Character) then --// Checking if the Character exists
local CharacterParts = Character:GetChildren() --// Getting everything inside of the Character, hats etc..
local BodyParts = {} --// empty table for filling in specific things inside the Character
for _,BodyPart in ipairs(CharacterParts) do --// Going throu everything inside the Char
if (BodyPart:IsA("BasePart") then --// Statement that tell us if it's a BodyPart or not
table.insert(BodyParts, BodyPart) --// If is out in table
end
end
for i = 1,#BodyParts do --// Loops throuh everything
BodyParts[i].Transparency = 0; BodyParts[i].CanColide = false --// Sets the things to make you a "ghost"
end
end
end)
Hope this helps you out, I would love to be more specific but you understand that this goes against the guidlines so I shouldn't be exactly helping you out
For you case, you need to use a generic for loop and :GetDescendants() to get all in character.
--< Script, ServerScriptService >--
game.Players.PlayerAdded:Connect(function(player) -- Get player on join in game
player.CharacterAdded:Connect(function(char) -- Detect character of player added
player.CharacterAppearanceLoaded:Wait() -- Wait for load all in character
for i,v in pairs(char:GetDescendants()) do -- Get all in character
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then -- Check if value(descendant) is a basepart and name of value(descendant) not is HumanoidRootPart
v.Transparency = 1 -- Set transparency to 1
v.CanCollide = false -- Set cancollide false
elseif v:IsA("Decal") then -- Check if value(descendant) is a decal to hide player face
v.Transparency = 1 -- Set transparency of decal to 1
end
end
end)
end)
Explaining:
- For loop
- Generic The for loop generic basically get all in a table with index,value i = index v = value example:
for i,v in pairs(workspace:GetDescendants()) do -- Get all objects in Workspace
print("Position in table: " .. i .. "\nBlock name: " .. v.Name)
end
- Numeric The for loop generic basically get all in a table with index, for get objects you need to use location:GetDescendants()[INDEX_NUMBER] i = index
- example of how to use the numeric for loop:
for iterator_variable = start value , end value , increment do
Example:
local location = workspace:GetDescendants() -- Location with :GetDescendants()
for i = 1,#location do
-- What is the #location, this basically get length of a table.
print("Position in table: " .. i .. "\nBlock name: " .. location[i].Name) -- Getting object with location[i] (location = location:GetDescendants())
end
- GetDescendants
- Returns an array containing all of the Instance's descendants Running this function will collect every object descending from this Instance and return them in an array For access the table you can use for loop(Generic/Numeric)
Example:
for i,v in pairs(workspace:GetDescendants()) do
print(v.Name) -- Print name of all descendants in workspace
end
- player.CharacterAppearanceLoaded:Wait()
Basically wait for all in character load.
Hope it helped :)
Wiki pages:
This discussion is preserved as it was. New answers, comments, and votes are closed.

9 comments
K thx
In my opinion it's better to at least let the person know how the code works so they can reuse that knowledge in the future. Now you just gave someone free code without them learning anything.
:wait() is deprecated. use :Wait() and you dont need to add bodypart in a table. and dont need to detect if player added. if you use playeradded you can get player: game.Players.PlayerAdded:Connect(function(player)
Fine, I will help him, brb
I do actually, I'm making it R6 and R15, separating everything but the BaseParts
you dont need to use a table.
No I get it, it works tho, thx again, I’m learning by reading, Ik some stuff
idk thats how I do it, you heard him it works anyway
If you can see my answer you will see how I meant it.