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.
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
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.
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)
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)