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

The output says that there are no problems with this code, but it doesn't work???

I tried to make a code for a chair that disappears once you click it and you can't touch it. I played my game but then only the seat disappeared when I clicked it. Here is my code:

local Part = script.Parent:GetChildren("Part")
local Seat = script.Parent:FindFirstChild("Seat")
 
function onClick()
        Part.Transparency = 1
        Part.CanCollide = false
        Seat.Transparency = 1
        Seat.CanCollide = false
    end
script.Parent.ClickDetector.MouseClick:connect(onClick) 

I put it into the output and it said that there were no errors. Help??

P.S. I should mention that there are many parts, not just one.

1 comment

0

On line 10 use :Connect(), :connect() is deprecated.

4 answers

✓ Accepted answer

Try doing this, it basically gets all the parts from script.Parent and changes their properties

local n = script.Parent:GetChildren()

for i, v in pairs(n) do
	if v:IsA("Part") then
		v.Transparency = 1
		v.CanCollide = false
	end
end

1 comment

0

Oh thanks! It worked but at first I had to write "function onClick()".

local Part = script.Parent:WaitForChild("Part")
local Seat = script.Parent:FindFirstChild("Seat")

function onClick()
        Part.Transparency = 1
        Part.CanCollide = false
        Seat.Transparency = 1
        Seat.CanCollide = false
    end
script.Parent.ClickDetector.MouseClick:connect(onClick) 

You used :GetChildren() instead of something like :WaitForChild(). :GetChildren() Would Return a Table of all the children while :WaitForChild() would wait for that object to load before proceeding the rest of the code.

1 comment

0

Didn't work.

GetChildren() gets all of the children in an object.

local Part = script.Parent:FindFirstChild("Part")
local Seat = script.Parent:FindFirstChild("Seat")

function onClick()
	Part.Transparency = 1
	Part.CanCollide = false
	Seat.Transparency = 1
	Seat.CanCollide = false
    end
script.Parent.ClickDetector.MouseClick:Connect(onClick)

1 comment

0

No only one of the parts disappeared.

I played your game and I know what you mean. Try doing this. When you click on the chair, destroy the chair. Then add a script that puts the chair in your backpack.

local model = [The model of the chair]

function onClick()
	model:Destroy()
    end
script.Parent.ClickDetector.MouseClick:connect(onClick) 

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