Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a Brick that when you step in. Your Body will be Invisible?

I wanna know the script that can make your Body Invisible like, When you step on a Brick. Your body will Invisible. But how?

3 answers

local part = Workspace.Part
part.Touched:connect(function(hitPart)
    local player = Game.Players:GetPlayerFromCharacter(hitPart.Parent)
    if player then
        for index, object in pairs(player.Character:GetChildren()) do 
            if object:IsA("BasePart") then 
                object.Transparency = 1 
                if object:FindFirstChild("face") then 
                    object.face.Transparency = 1 
                end 
            elseif object:IsA("Hat") and object:FindFirstChild("Handle") then 
                object.Handle.Transparency = 1 
            end
        end
    end
end)

part.TouchEnded:connect(function(hitPart)
    local player = Game.Players:GetPlayerFromCharacter(hitPart.Parent)
    if player then
        for index, object in pairs(player.Character:GetChildren()) do 
            if object:IsA("BasePart") and object.Name ~= "HumanoidRootPart" then 
                object.Transparency = 0
                if object:FindFirstChild("face") then 
                    object.face.Transparency = 0
                end 
            elseif object:IsA("Hat") and object:FindFirstChild("Handle") then 
                object.Handle.Transparency = 0
            end
        end
    end
end)
-- Make this a local script in the brick.
Part = game.Workspace.Part -- Rename the second part to the brick
Player = game.Players.LocalPlayer
Character = Player.Character

function onTouched ()
	Character.("Right Arm").Transparency = 0
	Character.("Left Arm").Transparency = 0
	Character.("Right Leg").Transparency = 0
	Character.("Left Leg").Transparency = 0
	Character.Torso.Transparency = 0
	Character.Head.Transparency = 0
end

script.Parent.Touched:connect(onTouched)

1 comment

0

How this helps/works.

So you have your brick right? It is named something like "Part". You can use a Touch function in a script to make you invisible when you touch it with something like this:

function onTouched(part)
	if part.Parent.Humanoid ~= nil then --if the part's parent contains a humanoid (probably a player) then
		p = part.Parent:GetChildren() -- Gets children of part's parent into a table
		for i = 1,#p do --loops for the as many times as the # of p
			if p[i]:IsA("Part") then --if child of the character is a part then
				p[i].Transparency == 1 --set the transparency to 1 (invisible)
			end
		end
	end
end -- closes the function

script.Parent.Touched:connect(onTouched) --This connects the function to the touched event. It will work in this format only if the part is the script's parent

This script would belong as a child of the brick you want to be the touch button.

This script creates a function that is triggered by the touching event. If the part that touches it has a parent that has a humanoid child (it is probably a player), it will run through the player's objects and if they are parts it will turn them invisible. This script could be reversed by changing the 1 in the Transparency line to 0.

Hope it helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.