I’m having difficulty creating a system where a box is required to press a button. Some elements are already working, such as placing the box on top of the PressurePlate to trigger a function. However, when the box is removed, nothing happens, and I’m not sure why.
local PressurePlate = script.Parent
local Center = PressurePlate.Center
local BoxsName = "Box20A"
local TWPart = workspace.StonePassage20A
local TweenService = game:GetService("TweenService")
local TInfo = TweenInfo.new(2, Enum.EasingStyle.Circular, Enum.EasingDirection.Out, 0, false, 0)
local Goal = {}
local Animation = TweenService:Create(TWPart, TInfo, Goal)
local BoxOnDebounce = false
--Make Passage
Center.Touched:Connect(function(hit)
if hit:IsA("Part") and hit.Name == BoxsName and (not BoxOnDebounce) then
BoxOnDebounce = true
print("box is on")
--Turn Neon Thingy On
task.spawn(function()
local NeonPartOn = {
Color = Color3.fromRGB(255, 26, 26),
Sound = PressurePlate.NeonParts:WaitForChild("NeonOnSound")
}
if hit:IsA("Part") and hit.Name == BoxsName then
local newCFrame = Center.CFrame + Vector3.new(0, -0.25, 0)
TweenService:Create(Center, TInfo, {CFrame = newCFrame}):Play()
Center.CanTouch = false
for _, v in PressurePlate.NeonParts:GetChildren() do
if v:IsA("Part") then
v.Color = NeonPartOn.Color
NeonPartOn.Sound:Play()
wait(0.05)
end
end
else
print("not box")
end
end)
--Make Passage
for _, v in pairs(TWPart:GetDescendants()) do
if v:IsA("Part") or v:IsA("UnionOperation") then
local MovingStoneSound = v.MovingStoneSound
MovingStoneSound:Play()
Goal = {Position = v.Position + Vector3.new(0, 13, 0)}
TweenService:Create(v, TInfo, Goal):Play()
wait(1)
end
end
end
Center.TouchEnded:Connect(function(hit)
wait(1)
if hit:IsA("Part") and hit.Name == BoxsName and BoxOnDebounce then
BoxOnDebounce = false
print("box is off")
task.spawn(function()
local NeonPartOff = {
Color = Color3.fromRGB(8, 8, 8),
Sound = PressurePlate.NeonParts:WaitForChild("NeonOnSound")
}
if hit:IsA("Part") and hit.Name == BoxsName then
local newCFrame = Center.CFrame + Vector3.new(0, -0.25, 0)
TweenService:Create(Center, TInfo, {CFrame = newCFrame}):Play()
for _, v in PressurePlate.NeonParts:GetChildren() do
if v:IsA("Part") then
v.Color = NeonPartOff.Color
NeonPartOff.Sound:Play()
wait(0.05)
end
wait(1)
end
end
end)
end
end)
end)