-- Bind drawer opening function to remote event

for _, Child in pairs(dresser:GetChildren()) do
	if Child.ClassName == "Model" and Child.Name == "Drawer" then
		Child.DrawerPadding.ROBLOXInteractionEvent.OnServerEvent:connect(function(player, arguments)
			openDrawer(player, Child)
		end)
		Child.PrimaryPart = Child.Front
	end
end

while true do
	for _, drawer in pairs(dresser:GetChildren()) do
		if drawer.ClassName == "Model" and drawer.Name == "Drawer" then
			local drawerStep = drawer.Front.CFrame.lookVector.unit * stepDistance
			if drawer.Open.Value and drawer.Step.Value < 20 then
				drawer:SetPrimaryPartCFrame(drawer.Front.CFrame + drawerStep)
				drawer.Step.Value = drawer.Step.Value + 1
			end
			if not drawer.Open.Value and drawer.Step.Value > 0 then
				drawer:SetPrimaryPartCFrame(drawer.Front.CFrame - drawerStep)
				drawer.Step.Value = drawer.Step.Value - 1
			end
		end
	end
	wait()
end
