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

How do I make the part disappear from script?

I'm doing a roblox Obby were when you touch a part that part disappears and then you can fall through it but when I touch the part it doesn't do anything but the script says it's working.

function onTouched (Obj)
	script.Parent.Transparency = Transparency.new ("1")
	script.Parent.CanCollide = CanCollide.new (False)
end

2 comments

0

You don't need to instantiate anything to represent a primitive data type.

0

you don't have to make a new value to do it

4 answers

In your code You need to type

script.Parent.Transparency = 1

and not

transparency.new

The same thing for

script.Parent.CanCollide = CanCollide.new (False)

its gonna be

script.Parent.CanCollide = false

I think you are trying to apply to Java, but remember, this is Roblox Lua. You don't have to create the instance for the values.

Also, checking the Obj parameter (what touched it) if it is a player is a player or not. Use humanoid since only players and NPCs have humanoids.

You also never called this function if the part was touched, so add an event there.

Your code should look like this:

function onTouched(Obj)
	if Obj.Parent:FindFirstChild("Humanoid") then
    		script.Parent.Transparency = 1
    		script.Parent.CanCollide = False
        end
end

script.Parent.Touched:Connect(onTouched())

Actually, actually.. Second answer is partially wrong. Do this code:

function onTouched(obj)
	if obj.Parent:FindFirstChild("Humanoid") then
		script.Parent.Transparency = 1
		script.Parent.CanCollide = false
	end
end

script.Parent.Touched:Connect(onTouched)

There are alot of stuff wrong with second answer by CrypxticDoge. Roblox doesn't use capitalized bools (such as in python which does False), so all you have to do is

script.Parent.CanCollide = false

and you don't use "()" on connecting premade functions, so all you have to do is

script.Parent.Touched:Connect(onTouched)

Here is an easier way to write it out

local part = script.Parent

part.Touched:Connect(function()
	part.Transparency = 1
	part.CanCollide = false
end

hope this helps

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