Hello, I'm making a puzzle where if two people stand on a button together, a part dissapears. If one of them leaves, it will reappear.
This is what I have:
local TweenService = game:GetService("TweenService")
local didOnce = true
local box = script.Parent
local names = {}
box.Touched:Connect(function(object)
if (object.Name == "Torso" or object.Name == "Left Leg" or object.Name == "Right Leg"
or object.Name == "Head" or object.Name == "LeftArm" or object.Name == "Right Arm"
or object.Name == "HumanoidRootPart") then
if #names == 0 then
print("hi.")
table.insert(names,object.Parent.Name)
else
for x, c in pairs(names) do
if object.Parent.Name == c then
break
elseif x == #names then
table.insert(names,object.Parent.Name)
print(object.Parent.Name)
print(#names)
if #names == 2 then
if didOnce then
workspace.Puzzle.DesertArchTwoButton2.SandstoneWall1.CanCollide = false
workspace.Puzzle.DesertArchTwoButton2.SandstoneWall1.Transparency = 1
didOnce = false
end
end
end
end
end
end
end)
box.TouchEnded:Connect(function(object)
if (object.Name == "Torso" or object.Name == "Left Leg" or object.Name == "Right Leg"
or object.Name == "Head" or object.Name == "LeftArm" or object.Name == "Right Arm"
or object.Name == "HumanoidRootPart") then
if #names == 0 then
print("hi.")
table.insert(names,object.Parent.Name)
else
for x, c in pairs(names) do
if object.Parent.Name == c then
break
elseif x == #names then
table.insert(names,object.Parent.Name)
end
end
end
if(#names < 2) then
workspace.Puzzle.DesertArchTwoButton2.SandstoneWall1.CanCollide = true
workspace.Puzzle.DesertArchTwoButton2.SandstoneWall1.Transparency = 0
end
end
end)
However, this does not function when someone leaves the button. Does anyone have a solution?
