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?
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 i,v in pairs(workspace:GetDescendants()) do -- Get all objects in Workspace print("Position in table: " .. i .. "\nBlock name: " .. v.Name) end
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
Example:
for i,v in pairs(workspace:GetDescendants()) do print(v.Name) -- Print name of all descendants in workspace end
Basically wait for all in character load.
Hope it helped :)