Align position instance activation through button script issue (Constraint-based elevator)

Made an elevator with constraints physics using align position and bodymovers (bodygyro), and despite having all correct parent referencing through my script along with both align position instances disabled by default, my script refuses to work (potentially because of unreachable code I’m guessing?). Anyways I came here looking to see if I could get some help on how to solve this because all I need the elevator is to simply either go up or down according to the config folders located in the button models.
Explorer reference for buttons:
image

Explorer reference for elevator floor part:
image
Code:

local hitbox  = script.Parent.Parent
local elevator = script.Parent.Parent.Parent.Parent.Parent.Elevator
local config = script.Parent.Parent.Parent.Configuration

hitbox.ClickDetector.MouseClick:Connect(function()
	
	if config.Up == true then
		if config.Down == true then
			error("You have both up and down settings for "..hitbox.Parent.Name.." enabled! Elevator will not be activated to ensure physics safety")
		else	
			elevator.Up.Enabled = true
			wait(10)
			elevator.Up.Enabled = false
		end
	
	end
	
	if config.Down == true then
		if config.Up == true then
			error("You have both up and down settings for "..hitbox.Parent.Name.." enabled! Elevator will not be activated to ensure physics safety")
		else	
			elevator.Down.Enabled = true
			wait(10)
			elevator.Down.Enabled = false
		end
	end
end)

0 errors are presented in the output so I have no idea what’s going on. Any assistance?

For every config.Up and config.Down, use config.Up.Value and config.Down.Value instead.

Also minor note, since your elevator is only going up or down, you could just use 1 BooleanValue that makes the elevator go up when true and down when false.

And you don’t need those conditional statements.

local sensor  = script.Parent
local elevator = script.Parent.Parent.Parent.Parent.Parent.Elevator
local direction = script.Parent.Parent.Parent.Configuration.BOOLVALUE

local reference = {
	[true] = "Up",
	[false] = "Down"
}

local debounce = false

sensor.MouseClick:Connect(function()
	if debounce then return end
	debounce = true
	
	direction.Value = not direction.Value

	local alignPos = elevator[reference[direction.Value]]
	alignPos.Enabled = true
	task.wait(10)
	
	alignPos.Enabled = false
	
	debounce = false
end)
1 Like